?
Solved

PHP - Where is there error reporting?

Posted on 2014-10-26
18
Medium Priority
?
119 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
[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
  • 5
  • 4
  • 3
  • +4
18 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 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 31

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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

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

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 58

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 111

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
 
LVL 111

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 111

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 111

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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