Redirect to user error page if there is an error on the page

I am new to web development PHP. I want to know if there is any code in PHP that redirects me to a page (lets call it "myerrorpage.php") if there is some error on the page?

In JSPcan use the following code

<%@ page errorPage="myerrorpage.jsp" %>

I want to know if there are any above JSPcode type in php? yes, then please help.
Any help is appreciated.

+4
source share
4 answers

php , , , , .

, , set_error_handler.

, set_exception_handler.

yourerrorpage.php, PHP- .

<?php
function error_found(){
  header("Location: yourerrorpage.php");
}
set_error_handler('error_found');
?>

, header("Location: page.php"); .


Apache

+3

php, .htaccess.Create.htaccess

ErrorDocument 400/400.html

ErrorDocument 401/401.html

ErrorDocument 403/403.html

ErrorDocument 404/404.html

ErrorDocument 500/500.html

ErrorDocument 502/502.html

ErrorDocument 504/504.html

400.html, 401.html .. . .

+1

, :

header('Location: myerrorpage.php');

, header(), . , , ().

0

..
, httpd.conf , xampp/apache/conf/httpd.conf

  • < Directory "C:/xampp/htdocs" > .
  • #AllowOverride All
  • "#", , .

, , - ".htaccess" .

  • , .htaccess
  • , (Sublime, Atom, Notepad ++ ..)
  • ....

.

ErrorDocument 404 YourDirectory/error page

.

ErrorDocument 404 http://localhost/project/error.php
0

Source: https://habr.com/ru/post/1542760/


All Articles