Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果发生错误,是否通过php重定向到另一个页面?_Php_Redirect_Error Handling - Fatal编程技术网

如果发生错误,是否通过php重定向到另一个页面?

如果发生错误,是否通过php重定向到另一个页面?,php,redirect,error-handling,Php,Redirect,Error Handling,我必须检查页面是否有错误,如果有错误,我必须重定向到一个默认页面,如error.php 我已经尝试了以下链接,但我无法得到结果 my.htaccess中的更改 ErrorDocument 400 /errors.php ErrorDocument 403 /errors.php ErrorDocument 404 /errors.php ErrorDocument 405 /errors.php ErrorDocument 408 /errors.php ErrorDocument 500 /e

我必须检查页面是否有错误,如果有错误,我必须重定向到一个默认页面,如error.php

我已经尝试了以下链接,但我无法得到结果

my.htaccess中的更改

ErrorDocument 400 /errors.php
ErrorDocument 403 /errors.php
ErrorDocument 404 /errors.php
ErrorDocument 405 /errors.php
ErrorDocument 408 /errors.php
ErrorDocument 500 /errors.php
ErrorDocument 502 /errors.php
ErrorDocument 504 /errors.php
myerrors.php代码

<?php
$urPath= $_SERVER['PHP_SELF'];
$fle =basename($urPath);
$finstr =str_replace("$fle","","$urPath");
$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
       400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
       403 => array('403 Forbidden', 'The server has refused to fulfil your request.'),
       404 => array('404 Not Found', 'The page you requested was not found on this server.'),
       405 => array('405 Method Not Allowed', 'The method specified in the request is not allowed for the specified resource.'),
       408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
       500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
       502 => array('502 Bad Gateway', 'The server received an invalid response while trying to carry out the request.'),
       504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);

$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
       $message = 'Please supply a valid HTTP status code.';
}

echo '<h1>Hold up! '.$title.' detected</h1>
<p>'.$message.'</p>';
?>
<!DOCTYPE html> 
<html> 
<head> 
    <title>Error</title> 
    <meta name="apple-mobile-web-app-capable" content="yes" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="<?php echo $finstr;?>css/token-input.css" rel="stylesheet" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/jquery.mobile-1.2.0.min.css" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/app-reset.css" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/jquerymobilecrm.min.css" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/jqm-datebox.css" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/dcr_css.css" />
    <link rel="stylesheet" href="<?php echo $finstr;?>css/jQueryValidationEngine.css" />
    <script src="<?php echo $finstr;?>js/jquery-1.8.1.min.js"></script>
    <script src="<?php echo $finstr;?>js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/jquery.tokeninput.js"></script>
    <script src="<?php echo $finstr;?>js/jquery.mobile-1.2.0.min.js"></script>
    <script src="<?php echo $finstr;?>js/logout.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/jqm-datebox.core.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/jqm-datebox.mode.datebox.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/jQueryValidationEngine-en.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/jQueryValidationEngine.js"></script>
    <script type="text/javascript" src="<?php echo $finstr;?>js/dateValidation.js"></script>
    <style type="text/css">
        .data-clear{
        height:35px;
        width:100%;
        }
    </style>    
    <?php //require_once"header.php";?>
</head> 
<body> 
<div data-role="page" id="addDialysis">
    <div data-role=header data-theme="a" data-position="fixed" style="height:40pt;">
        <h1 align="left" style="color: white;margin-top: 10pt;">Error Page</h1>
        <a href="home.php" data-icon="home" data-role="button" data-theme="reset" rel="external" style="margin-top:5pt;"><span style="padding-left: 14px;color: white;">Home</span></a>
    </div>
    <div data-role=fieldcontain>
            <div style="margin-left:45%"><p>Error Occurred !!!</p></div>
    </div>
</div>
</body>
</html>

错误

您正在使用本地服务器/本地主机吗

/errors.php将引用您的基本url,例如
http://localhost/errors.php
。如果您正在使用项目目录(例如
http://localhost/project_dir/
),errors.php文件的路径应为/project\u dir/errors.php


有了这个变化,,代码在我的系统上运行得很好。

运行代码时到底发生了什么?它显示默认错误页面…您是否在磁盘上以及您的问题中错误地拼写了
.htaccess
文件?磁盘中没有问题…我的路径类似于CRM/mobile/So/CRM/mobile/errors.php,因为.htaccess文件中的ErrorDocument路径不起作用?i像上面那样更改了它,但它不会出现。