2013-07-08 65 views
0

我要檢查渡過頁是有錯誤,如果錯誤是在那裏,我必須重定向到一個默認的頁面像error.php通過php重定向到另一個頁面?

我曾與下面的鏈接嘗試,但我不能得到的結果

改變我的.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 

errors.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> 

建議我任何的想法,在此先感謝..

+0

運行代碼時究竟發生了什麼? –

+0

它顯示默認錯誤頁面... –

+0

你是否在磁盤上以及在你的問題拼寫'.htaccess'文件不正確? – RiggsFolly

回答

1

你是工作在本地服務器上/本地主機?

/errors.php會引用您的基本網址,例如, http://localhost/errors.php。如果您正在使用項目目錄(例如http://localhost/project_dir/),則errors.php文件的路徑應爲/project_dir/errors.php。

通過此更改,代碼可以在我的系統上正常工作。

+0

沒有人,它現在不工作,我現在也... –

+0

我的路徑是像CRM /移動/ –

+0

所以/CRM/mobile/errors.php作爲您的ErrorDocument路徑.htaccess文件不起作用? – Pieter

相關問題