Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/50973-parse-error-redirect/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250773
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250786
Share on other sites

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.

 

;)

Link to comment
https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250793
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/50973-parse-error-redirect/#findComment-250873
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.