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

如何設置 cookie 然后在 PHP 中重定向?

How can I set a cookie and then redirect in PHP?(如何設置 cookie 然后在 PHP 中重定向?)
本文介紹了如何設置 cookie 然后在 PHP 中重定向?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

經過一些處理后,我想為用戶輸入設置一個 cookie 值,然后將它們重定向到一個新頁面.但是,cookie 沒有被設置.如果我注釋掉重定向,則 cookie 設置成功.我認為這是某種標題問題.這種情況的最佳解決方法是什么?

After doing a bit of processing, I want to set a cookie value to user input and then redirect them to a new page. However, the cookie is not getting set. If I comment out the redirect, then the cookie is set successfully. I assume this is a header issue of some sort. What is the best workaround for this situation?

if($form_submitted) {
    ...
    setcookie('type_id', $new_type_id, time() + 60*60*24*30);
    header("Location: $url");
    exit;
}

請注意,無論哪種情況,setcookie 都會返回 true 并且我沒有收到任何錯誤/警告/通知.

Note that setcookie returns true in either case and I get no errors/warnings/notices.

我使用的是 Unix/Apache/MySQL/PHP

I am using Unix/Apache/MySQL/PHP

推薦答案

如果您有人工 url 或子文件夾(如 www.domain.com/path1/path2/),那么您必須將 cookie 路徑設置為/以適用于所有人路徑,而不僅僅是當前路徑.

If you have human urls or subfolders (like www.domain.com/path1/path2/), then you must set cookie path to / to work for all paths, not just current one.

if($form_submitted) {
    ...
    setcookie('type_id', $new_type_id, time() + 60*60*24*30, '/');
    header("Location: $url");
    exit;
}

來自 PHP 手冊:

服務器上的路徑cookie 將可用.如果設置為'/', cookie 將可用整個域內.如果設置為'/foo/', cookie 只會是在/foo/目錄中可用以及所有子目錄,例如/foo/bar/域的.默認的值是當前目錄正在設置 cookie.

The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain . If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

這篇關于如何設置 cookie 然后在 PHP 中重定向?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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久久久国产精品 | 中文字幕在线中文 | 免费日韩av网站 | 91精品国产一区二区三区动漫 | 国产精品美女一区二区三区 | 色伊人网 | 久久久久国产成人精品亚洲午夜 | 日本精品视频一区二区 | 国产精品免费高清 | 亚洲 欧美 日韩 精品 | www.日韩欧美 | 国产超碰人人爽人人做人人爱 | av毛片 | 日韩欧美三区 | 在线视频亚洲 | 国产精品一区二区无线 | 亚洲一区国产 | 日韩精品在线一区 | 日韩中文字幕在线观看 | 日韩精品在线观看一区二区三区 | 午夜免费视频观看 | 亚洲精品久久久久久久久久吃药 | 国产福利在线 | 国产精品视频久久久 | 久热爱| 日本一区二区高清不卡 | 国产高清视频在线观看 | 91精品国产92 | www.日韩欧美 | 国产精品久久国产精品 | 91精品久久久久久久久 | 看一级黄色毛片 | 九九热re| 午夜在线影院 | 国产精品视频在线播放 | 日本天天操 | www.久久久久久久久久久久 | 亚洲视频中文字幕 | 亚洲精品一区二区在线观看 | 欧美xxxⅹ性欧美大片 | 91久久久久久久久久久久久 |