?
Solved

PHP Errors not displaying

Posted on 2014-01-09
8
Medium Priority
?
292 Views
Last Modified: 2014-02-24
I've been trying to troubleshoot an issue with one of my websites where if there is an error nothing is displayed, however the log file stores the error message.

In my PHP script I  have put at the top of my script:-
error_reporting(E_ALL);
ini_set('display_errors', '1');

Open in new window


But still no errors are being displayed, yet in my log files I have:-

[Thu Jan 09 21:22:27 2014] [warn] [client 192.168.1.1] mod_fcgid: stderr: PHP Notice: Undefined index: col2 in /var/www/testTable.php on line 132

What am I doing wrong which is not showing my errors?

Thank you in advance
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 288 total points
ID: 39769555
Top of the page add
<?php
error_reporting(E_ALL);
?>
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 856 total points
ID: 39769675
Who is your hosting company (Godaddy, by any chance)?  You should be able to get the errors visualized, and the hosting company should do this for you.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 856 total points
ID: 39769683
Also, it's not as good as seeing the error on the screen, but you can use this to scan the directory tree for the error_log file(s) and look at the contents.  I've had to do this before when a client was using GoDaddy.

<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THE ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo "</pre>";
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 856 total points
ID: 39769825
Godaddy does not turn off PHP error reporting.  Each and everyone of my errors on their hosting shows up on the screen.  So I can correct them of course.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 856 total points
ID: 39769873
Dave: I think this may be an opaque or hidden setting somewhere.  I have worked three GoDaddy accounts over the years and none of them displayed PHP errors.  If you got a failure, you got the white screen of death and nothing more.  Script settings for "display_errors" were simply ignored.  In my experience, the php_ini settings for "error_log" were obeyed, hence the script to find the error logs.

If you have the magic decoder ring that can tell us how to get them to divulge the errors, I'll buy you a beer, no matter how this question is resolved!

All the best, ~Ray
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 856 total points
ID: 39769954
I have never needed a "magic decoder ring" to display errors on Godaddy sites.  Out of a dozen web sites there including two of my own, I have never had that problem.  I've made enough errors to know also!

Now all of them have been running PHP 5.2 or higher so maybe they changed something.  Ten of the sites are on Linux and two on Windows.

I have put a copy of my PHP email demo on one of my Godaddy sites with an intentional error and you can clearly see the message there.  http://www.dibsiam.com/Email-error.php  This is the code.  You can see where I have commented out the variable to create the error.
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');

# more info in Email-hints.php
# some settings of vars
if (!isset($_POST['state']))  $state = ''; else $state = $_POST['state'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccTexth = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];
$header = "MIME-Version: 1.0\r\n";

$msgText = "$nameText $fromText ".date("F j, Y, g:i a")."\r\n".$msgText;
$subjectText .= ' '.date("Ymd-His");

if ($state == "")
{
    $title="Test Email Page";
    //$announce="---";
}
else
{
  $ccText="dmeweb@dibsplace.com";
  $toText="davebaldwin@dibsiam.com";
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
	$header .= "From: ".$fromText."\r\n";
	$header .= "Cc: ".$ccText."\r\n";
//	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "X-Priority: 1\r\n";
	$header .= "X-Mailer: PHP5.2\r\n\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header);
//	ini_restore(sendmail_from);
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
<!-- 
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
-->
</style>

</head>

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

<?php
   	echo ("State: ".$state."&nbsp;&nbsp;To: ".$toText."<br>\nSubject: ".$subjectText."<br>\n".$msgText."<br>\ncc: ".$header);
?>

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<!--   <form method="POST" action="<?php echo($PHP_SELF)?>"> -->
  <form method="POST" action="Email.php">
    <p><font size="3"><b>Name: <input type="text" name="nameText" size="46" value="Dave Baldwin"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" size="46" value="gammaboa@dibsplace.com"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail"></p>
    <input type="hidden" name="mailformat" value="Text"></p>
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60">This is the message that is was can be.  For you me and only.</textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  </form>
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

<input type=button value="Or Cancel - close This Window" onClick="javascript:window.close();">

</font>
</td></tr>
</table> 
</div>
<div align="center"><font face="Arial, Helvetica, sans-serif" size="1" color="#808080">
Web site design by <a href="http://www.dibsplace.com">Dave Baldwin</a></font></div>

</body>
</html>

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 856 total points
ID: 39769974
And here http://www.dibsiam.net/Email-error.php is the same file on Windows hosting.
0
 

Author Comment

by:tonelm54
ID: 39817770
I actually found that if I changed the type of hosting from CGI to Apache Module all my errors showed up, not quite sure why but it works now.

If everyone is agreeded, shall I just split the points between everyone?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question