Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-2007, 02:49 PM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Mod">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 887
Last Blog:
Wadio Media Layout Com...
Credits: 56
Rep Power: 15
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Php error handling

Quote:
When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks.
That's right, but how to remove those ugly error messages. Well it's simple.

Basic:
PHP Code:
<?php
$myFile 
fopen("myfile.txt""r");
?>

If your file don't exist you will receive error message like this:
Quote:
Warning: fopen(myfile.txt) [function.fopen]: failed to open stream: No such file or directory in /home/(something)/public_html/error.php on line 2
It's really simple to remove it. You can use this code:

PHP Code:
<?php
$myFile 
"myfile.php";
if(!
file_exists($file)){
die(
"Your file don't exist!");
}else{
$open fopen($myFile"r");
}
?>
Custom error handler:

Syntax
Code:
error_function(error_level,error_message, error_file,error_line,error_context)
How to set an error handler? It's simple:
PHP Code:
set_error_handler("YourFunctionInHere"); 
Example:
PHP Code:
<?php
function mycustomerror($errornumber$errormessage$errorfile$errorrow){ 
echo 
"<b>Error:</b> [$errornumber] $errormessage $errorfile $errorrow";
}
set_error_handler("mycustomerror");
?>
Okay now your error handler is set, let's try it.

PHP Code:
<?php
function mycustomerror($errornumber$errormessage$errorfile$errorrow){ 
echo 
"<b>Error:</b> [$errornumber] $errormessage $errorfile $errorrow";
}
set_error_handler("mycustomerror");
echo 
$myErrorTest;
?>
You will receive this error:
Quote:
Error: [8]Undefined variable: myErrorTest /home/(something)/public_html/error.php 6
I hope it helped..
Regards Jaan
__________________


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
| Need help? Send a
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


Last edited by Jaan; 03-02-2007 at 12:14 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-01-2007, 09:20 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,228
Last Blog:
Passwords
Credits: 857
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

ahhh fopen a php file...fun times
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-07-2008, 07:32 AM
acccapulco acccapulco is offline
Newbie
 
Join Date: Aug 2008
Posts: 5
Credits: 0
Rep Power: 0
acccapulco is on a distinguished road
Default Re: Php error handling

I am using very similar code:
PHP Code:
error_reporting (E_ALL);
function 
on_error ($num$str$file$line) {
        global 
$errors_buffer;
        
$errors_buffer[] = array('num'=>$num'str'=>$str'file'=>$file'line'=>$line);
}
set_error_handler("on_error"); 
In footer of my application I send e-mail containing $errors_buffer to myself. Users of my website doesn't see any errors and I have a message when something goes wrong.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-07-2008, 12:19 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,372
Last Blog:
Web slideshow in JavaS...
Credits: 1,276
Rep Power: 61
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Php error handling

I'll just stick with die().
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 4 end of life announcement Jordan Programming News 4 08-30-2007 09:55 AM
PHP Introduction clookid PHP Tutorials 10 01-16-2007 07:17 AM


All times are GMT -5. The time now is 04:52 PM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1047.22
marwex89 ........ 869.98
morefood2001 ........ 868.04
John ........ 857.15
WingedPanther ........ 761.06
Brandon W ........ 684.87
chili5 ........ 294.12
dargueta ........ 192.86
Steve.L ........ 192.06

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads