我寫了一個php代碼。地址欄神祕地起作用。任何人都可以解釋發生了什麼。爲什麼php header()如果頁面被添加書籤,這很奇怪?
的index.php
<?php
/* Notes:
* $_COOKIE['user_id'] is set and alive
* $_SESSION['user_id'] does not exist
* session_start() is given already
*/
...
session_start();
if(!isset($_SESSION['user_id') && isset($_COOKIE['user_id'])) {
$location = 'Location:http://localhost/project/login.php';
header($location);
}
?>
在地址欄中鍵入我 「本地主機/項目/ index.php文件」。它工作正常。
我收藏了「localhost/project/index.php」,這次我使用書籤去index.php。我希望被重定向到「本地主機/項目/ login.php中」
但是瀏覽器重定向我爲「localhost /項目/工程/ login.php中」
任何人都可以解釋這種現象給我嗎?
感謝
這是你的完整的腳本?你有重寫規則嗎?你有沒有註釋掉'header'來確認你輸入這個條件? – chris85
嗨Chris85, 問題是從這個if()語句。正如我所提到的,$ _SESSION ['user_id']死亡。 $ _COOKIE ['user_id']仍然存在,它仍然存在。 評論標題是什麼意思? – user7175892
'/ * header($ location); */die(「we're conditioning」);' – chris85