長話短說,我在從一個頁面到另一個頁面的程序中遇到了一個問題。當我創建一個用戶時,我本應進入登錄頁面。相反,我得到了 https://localhost/TEST/ROOTlogin 。我不完全確定我做錯了什么,但誰能給我指出正確的方法?
。if($result != "") {
echo "<div style='text-align:center;font-size:12px; color:white; background-color:gray;'> " 。
echo "<br>以下錯誤發生了。 <br><br> " 。
echo $result;
echo "</div>";
} else {
header("Location:". ROOT . "login")。
echo header;
死亡。
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
<?php
ini_set("display_errors", 1)。
函式 split_url() {
$url = isset($_GET['url']) ? $_GET['url'] : "home";
$url = explode("/", filter_var(trim($url,"/"), FILTER_SANITIZE_URL) )。
回傳$url。
}
$root = $_SERVER['REQUEST_SCHEME'] . "://" . $_server['server_name'] . $_server['php_self']。
$root = trim(str_replace("index.php", "", $root), "/")。
define("ROOT", $root . "/");
$URL = split_url();
如果(file_exists($URL[0] . ".php")) {
require($URL[0] . ".php")。
} else {
require("404.php")。
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
你需要確定你的重定向是否真的是你認為的那樣。所以第一步是列印出重定向字串,而不是重定向。
$header = 'Location: ' 。ROOT . 'login';
die($header);
// header($location)。
從這里開始,你將知道該以何種方式進行除錯。
如果$header不是你所期望的,使用同樣的技術來除錯錯誤發生的地方。
如果它是你所期望的,但是它重定向到其他地方,你就知道是你的服務器重寫的問題。 (提示:直接在瀏覽器中輸入重定向的網址進行測驗)
TBH,我將對重定向進行測驗。
TBH,我會放棄ROOT而使用header('Location: /login');,假設你的重寫正在做正確的事情。
uj5u.com熱心網友回復:
你可以這樣試一下:
。<?php
ini_set("display_errors", 1)。
函式 split_url($url = 'home') {
$url = explode("/", filter_var(trim($url,"/"), FILTER_SANITIZE_URL) )。
回傳$url。
}
$url = empty($_GET['url']) ? '' : $_GET['url'] 。
$URL = split_url($url);
$root = $_SERVER['HTTP_HOST'] . $_server['php_self'];
$root = trim(str_replace("index.php", "", $root), "/");
define('ROOT', $root . '/');
如果(file_exists($URL[0] . ".php")) {
require($URL[0] . ".php")。
} else {
require("404.php")。
}
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/306668.html
標籤:
