問題描述
一旦用戶在 PHP 中注冊,我想從一個域創建一個 cookie.并使這個 cookie 可以被其他 4 個域而不是子域訪問.我知道 cookie 并非設計為可供其他域訪問.例如,我從域 www.firstdomain.com 設置了一個 cookie 變量 $user_email 并希望在其他域中訪問它,例如 www.seconddomain.com、www.thirddomain.com 等.這可能可以使用 PHP 或 JavaScript 來完成.請有任何想法.
I want to create a cookie from one domain once the user is registered in PHP. and make this cookie accessible to 4 other domains not subdomain. I know that cookies are not designed to be accessible for other domains. For example I have set a cookies variable $user_email from domain www.firstdomain.com and want to access it in other domains like www.seconddomain.com, www.thirddomain.com etc. May be this can be done using PHP or JavaScript. Any idea please.
謝謝!
推薦答案
正如您已經說過的,只能為來自該域(包括其子域)的域設置 cookie.如果您的域不共享公共超級域,則需要為每個域單獨設置每個 cookie.
As you have already said, a cookie can only be set for a domain from that domain (including its subdomains). And if your domains do not share a common superdomain, you need set each cookie for each domain separately.
您可以使用在每個域上為您設置 cookie 的腳本來執行此操作.但請確保對這些腳本的請求進行身份驗證,以便只有您可以設置 cookie.
You can do this with a script that on each domain that sets the cookie for you. But make sure to authenticate requests to these scripts so that only you can set the cookies.
這篇關于多個域的 PHP Cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!