Why Your PHP Website Does Not Show Errorr When You Load A Page

Forums » PHP » Why Your PHP Website Does Not Show Errorr When You Load A Page
this page will help you troubleshoot on how you can display or show your php errors when you are debugin your code with a simple configuration in your web server
maintiaing a website if very difficutl. there are always people who will abuse spamming comments for many different websites. when i started my website, i used to have a guest comments page, but then i would see so many spam. i use thi php function to detect some spam., there were times when i need to debug my script by showing the errors on my website.. web servers now a day have display_errors off by default, you can fun phpinfo() if you dont know how your server is setup.. or you can view it in your php configuration file called php.ini.. 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);

i hope this helps.
ia
thanks, man

you really saved me a lot of searching :)

cheers,
i
Norman
hi im new in php programming, i having a problem when i run my code.

here is my sample code.

<?php

$user_name = "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);

if ($db_found) {
print "database found ";
mysql_close($db_handle);
{
print "database not found ";
}

?>

no error or display in web browser.

can you help me on this?

thanks!
wallpaperama
what you need to do is put this code in the very begining for your php file. it has to be the first line in the file:

ini_set('display_errors', 1);


when you put this code, it will show and dsiplay the error on the browser
wallpaperama
if that doesnt work, try putting this before ?>

echo mysql_error();
christalix
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 />";
}
?>
christalix
<?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
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 />";
}
?>

//<<<<<<<<<<<<<<<<<<<<<<<<<
Jurrien
yes! thank you ^^ you totally saved my day. good thing you turn up as search-result no.1 in google ;p
chris
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.
ok
Too much Thanks
John
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
Josephine
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
jezmyr
is it possible to display a custom page instead of blank page?
leandro
Thanks bro you saved me a lot of headaches.
Jimmy
Thank you very much!!.. You saved me from wasting more time just looking at a blank page cursing to my hosting provider!...
touchdeep
I can not leave this page without this comment.It works. Great. This is helpful and thank you very much.
loi
Thank you very much. It helps me a lot.
Srigowri
Thank you so much. This saved me from lot of hassle.
Peter
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 :)
Title: Why Your PHP Website Does Not Show Errorr When You Load A Page [966]
Tags: how to display php errors in my script code when display errors is disabled
By
Comments 20
Visits 122783