久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP - 為什么我不能擺脫這個會話 ID cookie?

PHP - why can#39;t I get rid of this session id cookie?(PHP - 為什么我不能擺脫這個會話 ID cookie?)
本文介紹了PHP - 為什么我不能擺脫這個會話 ID cookie?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試對網絡應用的注銷功能進行故障排除.當您登錄時,該應用程序為其域設置了多個 cookie.這是當前的注銷程序:

I'm trying to troubleshoot a logout function for a web app. When you're logged in, the app has several cookies set for its domain. Here's the current logout procedure:

  • 您單擊一個鏈接,該鏈接會將您轉到注銷頁面
  • 注銷頁面運行一個函數,該函數調用 session_destroy() 并循環訪問域的所有 cookie 并將它們設置為過去過期(請參閱下面的代碼)
  • 注銷頁面然后重定向到登錄頁面,這是純 HTML.
  • You click a link, which sends you to a logout page
  • The logout page runs a function that calls session_destroy() and also loops through all the cookies for the domain and sets them to expire in the past (see code below)
  • The logout page then redirects to a login page, which is straight HTML.

在此過程結束時,所有其他 cookie 都未設置,但 PHPSESSID cookie 仍然存在,具有相同的值,并且仍設置為在會話結束時過期.

At the end of this process, all the other cookies are unset, but the PHPSESSID cookie is still there, has the same value, and is still set to expire at the end of the session.

我在這里遺漏了什么?

這是我上面提到的注銷功能:

Here's the logout function I mentioned above:

function log_out_current_user() {

        // Destroy the session
        if (isset($_SESSION)) {
            session_destroy();
        }

        // Expire all of the user's cookies for this domain:
        // give them a blank value and set them to expire
        // in the past
        if (isset($_SERVER['HTTP_COOKIE'])) {
            $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
            foreach($cookies as $cookie) {
                $parts = explode('=', $cookie);
                $name = trim($parts[0]);
                setcookie($name, '', time()-1000);
                setcookie($name, '', time()-1000, '/');
            }
            // Explicitly unset this cookie - shouldn't be redundant,
            // but it doesn't hurt to try
            setcookie('PHPSESSID', '', time()-1000);
        }

    }

推薦答案

您沒有使用與創建時相同的參數來刪除它.使用 session_get_cookie_params 來獲取這些.為了便于攜帶,您應該通過 session_name 獲取 cookie 的名稱.這是一個小腳本來做到這一點:

You are not removing it with the same parameters as it was created. Use session_get_cookie_params to obtain those. To be portable you should get the name of the cookie via session_name. Here's a small script to do that:

$params = session_get_cookie_params();
setcookie(session_name(), '', 0, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));

這篇關于PHP - 為什么我不能擺脫這個會話 ID cookie?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 成人免费毛片在线观看 | 亚洲成色777777在线观看影院 | 精品视频一二区 | 亚洲国产欧美在线 | 美女爽到呻吟久久久久 | 一片毛片 | 69性欧美高清影院 | 亚洲毛片一区二区 | 午夜视频在线播放 | 久久久一区二区三区四区 | 欧美日韩成人在线 | www.久草.com| 久久99国产精一区二区三区 | 人人射人人草 | 国产精品a久久久久 | 欧美亚洲视频在线观看 | 国产在线精品一区二区 | 欧美国产精品一区二区三区 | www视频在线观看 | 97精品超碰一区二区三区 | 久久久精品一区二区三区 | 亚洲欧美自拍偷拍视频 | 国产精品成人一区二区 | 99精品网| 免费观看www7722午夜电影 | 国产98色在线 | 日韩 | 久国产精品 | 99福利视频| 国产亚洲欧美在线视频 | 久久成人一区 | 久久久网 | 久久久性 | 国产精品激情在线 | 欧洲一区二区三区 | 色999视频 | 亚洲 欧美 日韩 在线 | 91麻豆精品国产91久久久更新资源速度超快 | 日韩精品一区二区三区中文在线 | 日韩成人在线播放 | 日韩性生活网 | 国产成人精品久久 |