How to display PHP errors in My Script Code When display_errors is Disabled

Mobile
feeds
Welcome Login | Register

How to display PHP errors in My Script Code When display_errors is Disabled
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » PHP Forums
        » » How to display PHP errors in My Script Code When display_errors is Disabled
How to display PHP errors in My Script Code When display_errors is Disabled
Post Description: how to display php errors in my script code when display errors is disabled PHP
Post Tags:
This Post Has Been Viewed 10515 Times Since Mon Nov 06, 2006 10:43 pm Author bigger_travis with 13 replies
Next Post »» PHP __FILE__ directive is not working correctly, what can I do?
How to display PHP errors in My Script Code When display_errors is Disabled
Advertise On This Page




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:


Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it.
Embed:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : How to display PHP errors in My Script Code When display_errors is Disabled

Comments and replies About How to display PHP errors in My Script Code When display_errors is Disabled
:: 1 :: Reply #75643 Reply By tison On Wed Oct 15, 2008 1:17 pm
tison:
super useful, thank you, a must have for any developers tool belt
:: 2 :: Reply #78483 Reply By ia On Thu Oct 30, 2008 12:38 pm
ia:
thanks, man

you really saved me a lot of searching :)

cheers,
i
:: 3 :: Reply #96253 Reply By Norman On Sat Mar 07, 2009 6:58 am
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!
:: 4 :: Reply #96268 Reply By wallpaperama On Sat Mar 07, 2009 10:35 am
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
:: 5 :: Reply #96269 Reply By wallpaperama On Sat Mar 07, 2009 10:37 am
wallpaperama:
if that doesnt work, try putting this before ?>

echo mysql_error();
:: 6 :: Reply #111569 Reply By christalix On Tue Aug 04, 2009 3:49 am
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 />";
}
?>
:: 7 :: Reply #111570 Reply By christalix On Tue Aug 04, 2009 3:52 am
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 />";
}
?>
:: 8 :: Reply #111571 Reply By christalix On Tue Aug 04, 2009 3:57 am
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 />";
}
?>
:: 9 :: Reply #111572 Reply By christalix On Tue Aug 04, 2009 3:57 am
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 />";
}
?>
:: 10 :: Reply #111573 Reply By christalix On Tue Aug 04, 2009 3:57 am
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 />";
}
?>
:: 11 :: Reply #111574 Reply By christalix On Tue Aug 04, 2009 3:59 am
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 />";
}
?>

//<<<<<<<<<<<<<<<<<<<<<<<<<
:: 12 :: Reply #115196 Reply By Jurrien On Thu Sep 10, 2009 7:22 am
Jurrien:
yes! thank you ^^ you totally saved my day. good thing you turn up as search-result no.1 in google ;p
:: 13 :: Reply #142131 Reply By chris On Mon Aug 16, 2010 3:57 pm
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.