Wallpapers Forums Login

How To Display PHP Errors In My Script Code When Display_errors Is Disabled

If you are like many webmaster who are always making your website more secure, then you will benefit from this small simple tutorial guide on how to show your php errors. This helps when your web hosting isp or provider has turned off the display erorrs feature in the php.ini file.

Sometimes, your head turns trying to figure out what the problem is with your script. many times when the display_errors if off, you won't have a clue as to what the problem is unless you display the php errors.

this is how the php.ini file would look like:


QUOTE:

; - display_errors = Off [Security]
; With this directive set to off, errors that occur during the execution of
; scripts will no longer be displayed as a part of the script output, and thus,
; will no longer be exposed to remote users. With some errors, the error message
; content may expose information about your script, web server, or database
; server that may be exploitable for hacking. Production sites should have this
; directive set to off.

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = On


As you have read from the php.ini file above, having the display_errors on could have a security issue. so many web hosting companies turn it off, this is to protect your website from harm.

One way to display erorrs while the display_errors is off in the php.ini file, is to create write these functions at the beginning of your script files (.php files)

copy and paste this code
CODE:
ini_set('display_errors', 1);
 ini_set('log_errors', 1);
 ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
 error_reporting(E_ALL);


As for me, i had to learn the hard way. i was installing a gallery into my site and could not figure out what the problem was. this is what the gallery site had to say:

When diagnosing a problem, you want to be sure that you notice all hints that there might be. That's why you need to ensure that PHP is configured to display and log errors in such cases.

* Starting with Gallery 2.2, it suffices to put Gallery into its debug mode.
* In Gallery 2.0 and Gallery 2.1 (including 2.1.2), the debug mode doesn't enable displaying PHP errors yet. You'll need to enable it yourself.
* In rare cases, you also have to ensure that PHP errors are not just displayed, but also logged.

Also see: * How can I view the error log of the webserver?

By browsing to your Gallery's phpinfo page at http://www.example.com/gallery/lib/support/index.php -> PHPinfo, you can find all the configuration details of PHP we're interested in. And these are:

* display_errors (we want it to be On or 1)
* display_startup_errors (we want it to be On or 1)
* log_errors (we want it to be On or 1)
* error_log (it should be anything but undefined)
* error_reporting (it should be 2047 or larger)

You can ask your webhost to help you to put PHP into a configuration that is useful for debugging. Or you can open Gallery's main.php file in a text editor and replace:
Peter Sat May 05, 2012
Would just like to say, I always forget that code, even though I have been a PHP professional PHP developer for 2 years now. I always type in Google "show PHP errors" and I automatically click on this link. I thought I would spare 5 minutes by saying thanks a lot for the article! It has helped a lot :)
Srigowri Mon Apr 16, 2012
Thank you so much. This saved me from lot of hassle.
loi Sun Apr 15, 2012
Thank you very much. It helps me a lot.
touchdeep Tue Feb 28, 2012
I can not leave this page without this comment.It works. Great. This is helpful and thank you very much.
Jimmy Sun Oct 16, 2011
Thank you very much!!.. You saved me from wasting more time just looking at a blank page cursing to my hosting provider!...
leandro Thu Sep 08, 2011
Thanks bro you saved me a lot of headaches.
jezmyr Sun May 08, 2011
is it possible to display a custom page instead of blank page?
Josephine Thu Feb 10, 2011
Am having major problems with a php file I put in this suggested lines of code and it just displayed them at the beginning of the content. The error didn't show up at all. Basically I have a problem with a app displaying all quotes instead of one quote. I know its something to do with the index.php file but I cant determine what.

If I put in <? before the array the whole thing disappears. So I remove it but something isnt right and I am sure its those arguments that are causing the problem. thanks
John Thu Dec 16, 2010
I can't thank you enough man. You really saved my day. After hours of dealing with php.ini, I find this as the first result on Google.

Thank you
ok Wed Sep 22, 2010
Too much Thanks
chris Mon Aug 16, 2010
Hi,
I am currently writign a PHP postcard script as voluntary work and it doesn't work. So I used your error message to identify the problem and it states:

Notice: Undefined index: pdb2.awardspace dot com in /home/www/voluntary.award on line 24

Notice: Undefined index: voluntary.awardspace.co.u in /home/www/voluntary.award on line 24

$postcardURL = "".$_SERVER["pdb2. //problem is definetely here!!!

Please can someone explain this to me and how to fix it.
Jurrien Thu Sep 10, 2009
yes! thank you ^^ you totally saved my day. good thing you turn up as search-result no.1 in google ;p
christalix Tue Aug 04, 2009
this site is fc me up.

here it is not :

whil = mysql_fetch_array($result)){
ech $row;
echo "<br />";
}
?>

rather:

//>>>>>>>>>> = mysql_fetch_array($result)){
ech $row;
echo "<br />";
}
?>

//<<<<<<<<<<<<<<<<<<<<<<<<<
christalix Tue Aug 04, 2009
<?php

$user = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

// make a mysql connection
$query = "select * from addressbook";

$result = mysql_query($query) or die(mysql_error());


whil = mysql_fetch_array($result)){
ech $row;
echo "<br />";
}
?>
christalix Tue Aug 04, 2009
do this:


<?php

$user = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

// make a mysql connection
$query = "select * from addressbook";

$result = mysql_query($query) or die(mysql_error());


whil = mysql_fetch_array($result)){
ec $row;
echo "<br />";
}
?>

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5