php将json数据存入到cookie,php-使JQuery中的getJSON将cookie传递到外部域?

当我在JQuery中使用getJSON到外部域时,发出的请求不包含该域的cookie.我正在将其用于正在编写的分析脚本,并且需要在脚本运行所在的外部域上设置Cookie,以便跟踪唯一身份访问者.

domain1.com/website.html

domain2.com/tracker.js

//Get information about the user

info = "(here's some things about the user)";

//Send data using JSON

$.getJSON("http://domain2.com/getdata.PHP?"+info,function(data){}

);

domain2.com/getdata.PHP

/******

* Code to save data and stuff

*******/

//Get the current cookie (if any).

$current_tid = $_COOKIE['tID'];

//checks if the cookie is a string of 50 characters

if (strlen($current_tid)==50){

$TrackerID = $current_tid; //If the cookie already have a unique string,then use it!

} else {

$TrackerID = random_gen(50); //Generates a new random string with 50 characters

}

//Set cookie "tID" with the unique variable $TrackerID

setcookie("tID",$TrackerID,time()+60*60*24*365);

因此,事实是,当用户在server1上加载website.html时,用户也在server2上加载了tracker.js,后者将带有JSON的数据发送到getdata.PHP.但是,该脚本不会发送cookie,并且每次加载脚本时getdata.PHP都会生成一个新字符串.

有什么方法可以使用JSON发送Cookie?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值