最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to set a cookie for another domain using JavaScript? - Stack Overflow

programmeradmin0浏览0评论

Is it possible to set cookie in one domain and access the same in another domain?

Actually I need to set a cookie in A page when user clicks a button and then user needs to be redirected to B. But the cookies are working for the same domain but not for other domain.

Is it possible to set cookie in one domain and access the same in another domain?

Actually I need to set a cookie in A. page when user clicks a button and then user needs to be redirected to B.. But the cookies are working for the same domain but not for other domain.

Share Improve this question edited Jan 3, 2016 at 21:41 halfer 20.5k19 gold badges109 silver badges202 bronze badges asked Dec 2, 2015 at 14:51 user241674user241674 311 silver badge2 bronze badges 3
  • 1 stackoverflow./questions/3342140/cross-domain-cookies maybe you find answer here – Konstantin Zadiran Commented Dec 2, 2015 at 14:54
  • Possible duplicate of How to set a cookie for another domain – CoderPi Commented Dec 2, 2015 at 14:55
  • You can set a cookie in A. and redirect to a script on B. that will set a cookie for you. This approach generally uses hashing techniques so that B can tell that the request has e from an authorised source. – halfer Commented Jan 3, 2016 at 21:43
Add a ment  | 

3 Answers 3

Reset to default 4

No. You can only set cookies for the domain your script is currently running on.

Is it possible to set cookie in one domain and access the same in another domain?

No. That would be a security risk.

Cookies were designed for maintaining state, like user preferences. Would you like Joe Random Evil Site to be able to change your preferences for your Online Banking service?

if you have both A. and B., you can simply make a http (or https whatever) request from A to B and put on it whatever you want to pass to B. . B. gets the request, saves it serverside, when user enters the B., server sends back the data to user.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>