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

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

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

問題描述

我正在嘗試對網(wǎng)絡(luò)應(yīng)用的注銷功能進(jìn)行故障排除.當(dāng)您登錄時,該應(yīng)用程序為其域設(shè)置了多個 cookie.這是當(dāng)前的注銷程序:

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:

  • 您單擊一個鏈接,該鏈接會將您轉(zhuǎn)到注銷頁面
  • 注銷頁面運行一個函數(shù),該函數(shù)調(diào)用 session_destroy() 并循環(huán)訪問域的所有 cookie 并將它們設(shè)置為過去過期(請參閱下面的代碼)
  • 注銷頁面然后重定向到登錄頁面,這是純 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.

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

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);
        }

    }

推薦答案

您沒有使用與創(chuàng)建時相同的參數(shù)來刪除它.使用 session_get_cookie_params 來獲取這些.為了便于攜帶,您應(yīng)該通過 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']));

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

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

相關(guān)文檔推薦

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 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
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 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 成人黄色电影免费 | 欧美中文一区 | 特黄特色大片免费视频观看 | 一区二区三区四区在线 | 在线色网站 | 成人在线视频免费观看 | 免费色网址 | 蜜桃精品噜噜噜成人av | 成人超碰 | 成人免费一区二区三区视频网站 | 精品国产乱码久久久久久图片 | 波多野结衣一区二区 | 国产美女永久免费无遮挡 | 91久久精 | 亚洲一二三区精品 | 久久久激情视频 | 色网站在线 | 亚洲视频第一页 | 日本特黄a级高清免费大片 成年人黄色小视频 | 日韩欧美一级精品久久 | 欧美日韩国产精品一区二区 | 污片在线免费观看 | 成人国产精品色哟哟 | 亚洲一区二区三区欧美 | 亚洲毛片 | 欧美精品久久 | 国偷自产av一区二区三区 | 久久小视频 | 91视频88av| 欧日韩不卡在线视频 | 日本欧美在线 | 91黄在线观看| 久久久久久国模大尺度人体 | 久久激情网 | 久草新在线| 在线视频亚洲 | 黄色永久免费 | 日日夜夜天天 | 视频一区在线观看 | 国产成人精品一区二区三 | 亚洲精品二区 |