久久久久久久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)
主站蜘蛛池模板: 国产99久久 | 国产精品久久久久久久久久久久 | 欧美精品一区二区三区在线 | 看片wwwwwwwwwww | 亚洲精品一区二区三区蜜桃久 | 欧美亚州| 欧美特级黄色 | 五月网婷婷 | 中文字幕不卡一区 | 超碰欧美 | 日韩av一区二区在线 | 久久精品亚洲精品 | 日本淫视频 | 黑人巨大精品欧美一区二区免费 | 欧美久久久久久久 | www.国产| 亚洲av毛片| 亚洲人成人一区二区在线观看 | 影音先锋中文字幕在线观看 | 欧美一级免费看 | 国产福利一区二区 | 精品不卡 | 九九热视频这里只有精品 | 久在线观看| 欧美精品99 | 亚洲欧美日韩精品久久亚洲区 | 日韩在线播放av | 亚洲精品欧美 | 日韩一二区| 午夜电影网| 久久久天堂 | 欧美激情综合 | 国产欧美一区二区三区国产幕精品 | 国产美女精品视频 | 中文字幕电影在线观看 | 欧美日韩电影免费观看 | 亚洲视频中文字幕 | 超碰综合 | 国产日韩欧美一区 | 国产视频一二三区 | 国产999精品久久久久久 |