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:
Comments and replies About How to display PHP errors in My Script Code When display_errors is Disabled
tison:
super useful, thank you, a must have for any developers tool belt
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:
<?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:
<?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:
<?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.