dlf1987 Posted May 11, 2007 Share Posted May 11, 2007 lets say that a customer gets this error "parse error: parse error in C:\*****secret root *****\httpdocs\error.php on line 1" is there a way to have the customer redirected to an error page? i have custom error pages turn on in my plesk cp, but i cant figure out which one is for parsing errors. I got it to redirect if you went to a page that doesnt exists, but how do you that with pages that exists but has errors? thanks Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/ Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 If you are using PHP 5 I believe a try/catch would work, not sure. Because Parse errors are a special kind of errors and will kill the running of the whole script because it can't "compile" The custom plesk error pages are like 404 500 internal etc. Nothing to do with PHP really. Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250773 Share on other sites More sharing options...
chigley Posted May 11, 2007 Share Posted May 11, 2007 <?php set_error_handler("error"); function error($errno, $errstr, $errfile, $errline, $errcontext) { header("Location: errorpage.php"); } ?> Pretty simple, you can edit it to do only certain errors etc. Chigley Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250775 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 There you go, I guess you learn something new every day. Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250780 Share on other sites More sharing options...
dlf1987 Posted May 11, 2007 Author Share Posted May 11, 2007 i dont mean to be dumb, but where do i put it? and how do i use it? heres an example error that will cause a parse error <?php echo "error ?> how would you use that function to redirect to an error page with having that error above ??? thanks Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250783 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 I believe the usage would be like this: // error.inc.php <?php set_error_handler("error"); function error($errno, $errstr, $errfile, $errline, $errcontext) { header("Location: errorpage.php"); } ?> //test.php <?php include('error.inc.php'); // include for error handling echo "Testing me!!! echo 'How about this test?'; ?> Not tested but that is how I believe it would be used. Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250786 Share on other sites More sharing options...
chigley Posted May 11, 2007 Share Posted May 11, 2007 Yeah that's it. If you put that at the top of each page (or in an include) then edit the error() function to do what you want it to do with the error. Inside the error code you may just want to redirect it to a page saying "An error has occured" or you may want to die() or you may want to do something different! Just modify the error function until it does what you want it to do, using these variables in your code: $errno, $errstr, $errfile, $errline, $errcontext. Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250793 Share on other sites More sharing options...
dlf1987 Posted May 11, 2007 Author Share Posted May 11, 2007 i did it exactly as you said, still just shows parse error... is it because i have PHP Version 4.3.11? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250863 Share on other sites More sharing options...
chigley Posted May 11, 2007 Share Posted May 11, 2007 No it should work for PHP 4.3. :S Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250868 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 www.php.net/set_error_handler set_error_handler (PHP 4 >= 4.0.1, PHP 5) Should work, maybe try this ??? // error.inc.php <?php function error($errno, $errstr, $errfile, $errline, $errcontext) { echo 'There was an error on the page ' . $errno . '. Please report it to the site admin!'; } $errorHandler = set_error_handler("error"); ?> //test.php <?php include('error.inc.php'); // include for error handling echo "Testing me!!! echo 'How about this test?'; ?> If not check the user contributions at the page posted above. Quote Link to comment https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.