Solved

PHP Errors not displaying

Posted on 2014-01-09
8
253 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
8 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 72 total points
Comment Utility
Top of the page add
<?php
error_reporting(E_ALL);
?>
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 214 total points
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 214 total points
Comment Utility
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 82

Accepted Solution

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

Author Comment

by:tonelm54
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now