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

使用 PHP 或 JavaScript 在多個域上設置 cookie

Set cookie on multiple domains with PHP or JavaScript(使用 PHP 或 JavaScript 在多個域上設置 cookie)
本文介紹了使用 PHP 或 JavaScript 在多個域上設置 cookie的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有 3 個主題相同的域.如果有人選擇了不同的主題,我希望它在所有 3 個域中傳播,以便他們的體驗保持不變.

I have 3 domains that are themed the same. If somebody chooses a different theme, I want it to propagate across all 3 domains so their experience stays the same.

我打算通過在 domain1 上設置 cookie 來實現這一點,重定向到設置了 cookie 的 domain2,重定向到設置了 cookie 的 domain3,然后重定向回來.由于信息不需要安全或受保護,因此這將正常工作,不會出現實際問題.

I was planning to accomplish this by setting a cookie on domain1, redirect to domain2 where the cookie is set, redirect to domain3 where the cookie is set, redirect back. Since the information doesn't need to be secure or protected, this will work fine with no real problems.

我討厭 3 重定向只是為了在每個域上設置一個 cookie 并且正在尋找更優雅的東西.

I hate the idea 3 redirects just to set a cookie on each domain and was looking for something a little more elegant.

推薦答案

做 Google 正在做的事情.是的,Google 正在使用相同的技巧讓用戶登錄 YouTube 和不同域中的其他 Google 服務.

Do what Google is doing. Yes, Google is doing this same trick to login the user to YouTube and other Google services which are on different domains.

創建一個 PHP 文件,在所有 3 個域上設置 cookie.然后在要設置主題的域上,創建一個 HTML 文件,該文件將加載在其他 2 個域上設置 cookie 的 PHP 文件.示例:

Create a PHP file that sets the cookie on all 3 domains. Then on the domain where the theme is going to set, create a HTML file that would load the PHP file that sets cookie on the other 2 domains. Example:

<html>
   <head></head>
   <body>
      <p>Please wait.....</p>
      <img src="http://domain2.com/setcookie.php?theme=whateveryourthemehere" />
      <img src="http://domain3.com/setcookie.php?theme=whateveryourthemehere" />
   </body>
</html>

然后在 body 標簽上添加一個 onload 回調.該文檔僅在圖像完全加載時加載,即在其他 2 個域上設置 cookie 時.加載回調:

Then add an onload callback on body tag. The document will only load when the images completely load that is when cookies are set on the other 2 domains. Onload Callback :

<head>
   <script>
   function loadComplete(){
      window.location="http://domain1.com";//URL of domain1
   }
   </script>
</head>
<body onload="loadComplete()">

setcookie.php

我們使用 PHP 文件在其他域上設置 cookie,如下所示:

setcookie.php

We set the cookies on the other domains using a PHP file like this :

<?php
if(isset($_GET['theme'])){
   setcookie("theme", $_GET['theme'], time()+3600);
}
?>

現在 cookie 設置在三個域上.

Now cookies are set on the three domains.

來源 - 我的博客

這篇關于使用 PHP 或 JavaScript 在多個域上設置 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亚洲精品 | 草在线| 欧美激情精品久久久久久 | 久草成人| 国产免费观看久久黄av片涩av | 欧美日韩国产中文 | 国产精品永久免费视频 | 日韩精品在线看 | 亚洲成av片人久久久 | 国产乱码精品一区二区三区五月婷 | 国产乱码精品一区二区三区五月婷 | 欧美在线观看一区 | 国产国产精品久久久久 | 黄色大片视频 | 精品欧美一区二区三区久久久 | 欧美精品一区二区在线观看 | 免费国产一区二区 | 欧美精品一区三区 | 欧美一区成人 | 欧美炮房 | 国产一级在线观看 | 日本成人中文字幕在线观看 | 青青草久久 | 亚洲色图婷婷 | 亚洲精品乱码久久久久久久久 | 亚洲精品99久久久久久 | 日韩在线国产 | 午夜欧美 | 91私密视频| 精品国产乱码久久久久久88av | 亚洲风情在线观看 | 视频一二三区 | 国产成人精品a视频一区www | 99re视频在线| 国产一区二区三区免费观看视频 | 精品一级| 在线欧美亚洲 | 丁香久久| 国产1区2区在线观看 | 九九在线视频 | 国产在线1|