簡體   English   中英

注銷后按瀏覽器后退按鈕,它會重定向到具有本地主機地址的上一頁

[英]After logout pressing the browser back button it redirects to previous page with localhost address

我正在本地主機上開發登錄/注銷頁面。

當我使用 localhost/login.php 頁面登錄時,它會重定向到 localhost/index.php。

我的本地 ip 是 192.168.1.57 所以無論我輸入 localhost 還是 192.168.1.57 它都會重定向到 index.php 頁面。

On pressing logout button in this index.php, i am redirecting it to 192.168.1.57/logout.php (I am not using localhost/logout.php because i want to test it from different computer on same LAN) which is this:

session_start();
unset($_SESSION["user"]);
session_destroy();  
header("Location: ./login.php");
exit;

所以我又在 192.168.1.57/login.php 上。

但是當我在瀏覽器中按下“返回”按鈕時,它會將我重定向到 localhost/index.php。

所以我很困惑為什么 192.168.1.57 和 localhost 的行為不同。 為什么“192.168.1.57/logout.php”或“localhost/logout.php”不一樣。

好吧,我還沒有真正嘗試過這段代碼,但它可能會對你有所幫助

所以你可以使用類似的東西

$_SESSION["user"] = "";                                                                         
                                                                                                                                                                                                                                                                                                                 
echo"<script>
                                                                                                                                 
    if ( window.history.replaceState ) {
                                                                                                                                  
         window.history.replaceState( null, null, window.location.href );
                                                                                                                                 
     }                                                                                                                   
 </script>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM