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

為什么我的 cookie 沒(méi)有設(shè)置?

Why are my cookies not setting?(為什么我的 cookie 沒(méi)有設(shè)置?)
本文介紹了為什么我的 cookie 沒(méi)有設(shè)置?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有以下 PHP 函數(shù):

I have the following PHP function:

function validateUser($username){
    session_regenerate_id (); 
    $_SESSION['valid'] = 1;
    $_SESSION['username'] = $username;
    setcookie('username2',$username,time()+60*60*24*365);
    header("Location: ../new.php");
}

然后我獲取cookie:

And then I fetch the cookie:

echo $_COOKIE['username2'];exit();

(我只把 exit() 用于調(diào)試目的)

(I only put exit() for debugging purposes)

唯一的問(wèn)題,它出來(lái)是空白的.有什么想法嗎?

Only problem, it's coming out blank. Any ideas?

更新:函數(shù)是這樣調(diào)用的:

    if(mysql_num_rows($queryreg) != 0){
    $row = mysql_fetch_array($queryreg,MYSQL_ASSOC);
    $hash = hash('sha256', $row['salt'] . hash('sha256', $password));
    if($hash == $row['password']) {
        if($row['confirm'] == 1){
            if(isset($remember)){
                setcookie('username',$username,time()+60*60*24*365);
                setcookie('password',$password,time()+60*60*24*365);
            } else {
                setcookie('username','',time()-3600);
                setcookie('password','',time()-3600);
            }
            validateUser($username);

為了節(jié)省空間,我沒(méi)有包含所有的 if() 語(yǔ)句.

I didn't include all the if() statements to save some space.

推薦答案

嘗試添加路徑 =/,這樣 cookie 就適用于整個(gè)站點(diǎn),而不僅僅是當(dāng)前目錄(之前已經(jīng)引起我注意)

try adding the path = /, so that the cookie works for the whole site not just the current directory (that has caught me out before)

示例

setcookie('password',$password,time()+60*60*24*365, '/'); 

還要確保 cookie 是第一個(gè)被輸出的東西正如 php 手冊(cè)中所建議的那樣(這也讓我感到困惑)

also make sure the cookie is the first thing being output as advised in the php manual (this has caught me out before too)

像其他標(biāo)頭一樣,cookie 必須在您的任何輸出之前發(fā)送腳本(這是一個(gè)協(xié)議限制).

Like other headers, cookies must be sent before any output from your script (this is a protocol restriction).

這篇關(guān)于為什么我的 cookie 沒(méi)有設(shè)置?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
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ù)組自動(dòng)填充選擇框)
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)
主站蜘蛛池模板: 日韩精品一区在线 | 精精国产xxxx视频在线野外 | 色婷婷激情 | 亚洲综合色视频在线观看 | 日本一区二区三区精品视频 | 日日操日日舔 | 天堂av中文在线 | 二区精品 | 精品视频一区二区三区在线观看 | 国产精品美女久久久久久免费 | www.五月天婷婷.com | 久久免费视频1 | 亚洲精品中文字幕 | 欧美日韩1区2区 | 成人在线视频免费看 | 免费午夜视频 | 精品久久久久一区二区国产 | 九九热在线精品视频 | 日本一区二区三区视频在线 | 不卡在线一区 | 高清av一区| 日韩尤物视频 | 久久久久久国产一区二区三区 | 日本黄色短片 | 久久久久成人精品免费播放动漫 | 91精品国产91久久久久久不卞 | 久久lu | 欧美成年网站 | 国产成人免费网站 | 天天想天天干 | 欧美最猛黑人 | 国产电影一区二区在线观看 | www.日韩欧美| 91福利影院 | 日韩一区二区三区在线视频 | 亚洲精品久久 | 91福利在线观看视频 | 国产精品久久久久久久久久东京 | 色综合av| 国产精品成人一区 | 国产乱码精品一区二区三区中文 |