• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

PHP Errors not displaying

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
tonelm54
Asked:
tonelm54
7 Solutions
 
GaryCommented:
Top of the page add
<?php
error_reporting(E_ALL);
?>
0
 
Ray PaseurCommented:
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
 
Ray PaseurCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Dave BaldwinFixer of ProblemsCommented:
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
 
Ray PaseurCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
And here http://www.dibsiam.net/Email-error.php is the same file on Windows hosting.
0
 
tonelm54Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now