Solved

PHP - Where is there error reporting?

Posted on 2014-10-26
18
111 Views
Last Modified: 2014-10-28
Why does this produce no error output?

<?php
error_reporting(E_ALL);

ini_set('display_errors', 1);

include("header.php");
include("menu.php");
$info=urldecode($_GET["info"]);
$info=explode("%f ", $info);
$c=$_GET["c"];
$r=$_GET["r"];

$row=explode("%i ",$info[$r]);
 
echo "<div class=\"content\">";

echo "<table><tr><td>";
echo "<img id=\"pic\" src=\"",$row[0],"\" style=height:425px><td style=\"width:3%;\">";
echo "<td>",$row[1];
echo "<tr><td>All images copyright Linda Matthews.";
echo "<td><button onclick=\"prevPicture\"> Next </button>";
          <button onclick=\"history.go(-1);\"> Thumbnails </button>";
          <button onclick=\"nextPicture\"> Next </button>";
echo "</table></div>";

include("footer.php");


echo "<script type="text/javascript">"
echo "    function prevPicture {"
echo "        document.getElementById(\"pic\").src=\"art/zen03.jpg\";";
echo "    }";

echo "   function nextPicture {"
echo "        document.getElementById(\"pic\").src=\"art/zen04.jpg\";";
echo "    }";
echo "</script>";

Open in new window

0
Comment
Question by:padmasambhava
  • 5
  • 4
  • 3
  • +4
18 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40405628
Should there be an error?

Could be that the php.ini file is set to not display errors, in php.ini look for

display_errors = On

should be set to On
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40405673
After setting the above configuration, you need to restart the apache
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 40405766
Or you can put this line at the top of the script

ini_set("display_errors", "On");

Open in new window


Since these two statements don't take effect if there is a parse error (before an error be thrown it's necessary parse the entire file and if a parse error is found no code is executed), you could place these two line in one file (let's say 'main.php') and then iclude your actual file in this new one:

main.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", "On");
include("your_file.php");

Open in new window


Then try to execute main.php: the two statements referring to error reporting will be executed, then your file will be included and any error displayed.

Cheers
0
 

Author Comment

by:padmasambhava
ID: 40405768
It produces no output. It doesn't generate any html.
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 40405778
Even separating error code from the rest? Well, since I don't see any error in your code, try to look at the includeed files.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40405834
Try

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

set_error_handler("var_dump");
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 40406152
Added code tags ...

Sometimes ISP's turn off error reporting and you can't turn it on - so if you have tried the above try adding the following to an .htaccess in your root folder
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag  log_errors on
## Change the path below to match the path to your website
php_value error_log  /home/path/public_html/domain/PHP_errors.log;

Open in new window


Failing that some ISP's create a an error.log file automatically in the root - check to see if there is one there.

If that does not pan out - try creating your own error handler (Refer http://php.net/manual/en/function.set-error-handler.php for more information)
$old_error_handler = set_error_handler("myErrorHandler");
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    echo "Error {$errno}, {$errstr} in {$errfile} on line {$errline}";
}

Open in new window

Failing that try the brute force approach
Add output lines as shown below - you should get a trace of how far the application gets before terminating. The last output message should be the line just before the statement generating the error.
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
include("header.php");
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
include("menu.php");
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
$info=urldecode($_GET["info"]);
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
$info=explode("%f ", $info);
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
$c=$_GET["c"];
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
$r=$_GET["r"];
"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";

"File: " . __FILE__ . ", Line: " . __LINE__ . "<br/>";
$row=explode("%i ",$info[$r]);

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40406292
I use these settings in my php.ini file and I get errors reported and logged correctly.
display_errors = On
log_errors = On
log_errors_max_len = 1024
error_log = error_log

Open in new window

Once you have those settings turned on, this script should give you an expected error.
<?php trigger_error("Hello!", E_USER_ERROR);

Open in new window

0
 

Author Comment

by:padmasambhava
ID: 40406384
Where is the default location for php.ini and how do I restart apache?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40406405
php.ini is located in the WWW root directory and may be located in sub-directories if you need to change settings in the sub-directories.  You'll have to figure out how to restart the server on your own.  When in doubt, power-off/power-on will override a multitude of sins :-)
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40406617
are you using windows or linux? and do you use any software bundle like xampp or wamp server?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40406627
Location of php.ini and how you restart Apache will depend on your setup - windows, linux?

php.ini location
If it's windows then it will be in the PHP folder
If Linux then the etc folder

(definitely not in the www root)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40406652
I use Linux.  The php.ini file that is located in my WWW root applies my local preferred settings, and overrides the global settings.  

There may be other places on the server that have a php.ini file, but to say "definitely not in the www root" may give an incomplete understanding of the cascade of directives.  And our author might not want to mess with the global settings (or might not be able to change the global settings) -- at least not until we have a good understanding of the effect of these settings and the changes that might result from a change (or a mistake) in the parent version of php.ini.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40406681
Correct, I was thinking about something else
0
 

Author Comment

by:padmasambhava
ID: 40407143
I'm on a linux box. So I will try changing php.ini to make showing errors the default.
0
 

Author Comment

by:padmasambhava
ID: 40407578
php.ini seems to have no carriage returns. Is it safe to search for the string and change it in place or is there a process that I need to go through? No hurry I have to get access to change it anyway.
0
 

Author Closing Comment

by:padmasambhava
ID: 40407657
Thanks Gary and all.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40408220
For anyone coming upon this question in the future, please learn about this native PHP function:
http://php.net/manual/en/function.phpinfo.php
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

759 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

21 Experts available now in Live!

Get 1:1 Help Now