XMLHttpRequest 和唯一会话 ID PHP
我创建了一个javascript来通过PHP中的会话跟踪用户跨域,并用它知道用户是否在线,在javascript中我使用XMLHttpRequest并通过POST方法发送,通过函数setInterval来重复此跟踪,它有效对我来说很好,但是对于 XMLHttpRequest 中的每次调用,PHP 会话都会生成其他会话 ID,我只想要在线用户的唯一会话 ID。
PHP: header('Access-Control-Allow-Origin: *'); //允许跨域请求
Javascript:
var __url__rastreamento = "http://external-domain.com/rastreamento/"
var __rastreamento_tempo = 10000;
var __pagina__titulo = document.title;
var __url__requisicao = document.location.href.replace(window.location.protocol + "//" + window.location.host,"");
var __url__host = window.location.host;
var __x__h__r;
if (window.XMLHttpRequest)
{//IE7+, Firefox, Chrome, Opera, Safari
__x__h__r = new XMLHttpRequest();
}
else
{//IE6, IE5
__x__h__r = new ActiveXObject("Microsoft.XMLHTTP");
}
function recarregaRastreamento(){
__x__h__r.open("POST",__url__rastreamento ,true);
__x__h__r.setRequestHeader("Content-type","application/x-www-form-urlencoded");
__x__h__r.send("titulo=" + escape(__pagina__titulo) + "&host=" +escape(__url__host) + "&requisicao=" + escape(__url__requisicao));
}
setInterval("recarregaRastreamento()", __rastreamento_tempo);
提前致谢
i created a javascript to track users cross-domain over the Session in PHP and with it know if the user is online, in the javascript i'm using XMLHttpRequest and send by POST Method, over a function setInterval to repeat this track, it works fine to me, but for each call in XMLHttpRequest the PHP Session generate other Session ID, i want just Unique Session ID by user online.
PHP: header('Access-Control-Allow-Origin: *'); //allow cross-domain request
Javascript:
var __url__rastreamento = "http://external-domain.com/rastreamento/"
var __rastreamento_tempo = 10000;
var __pagina__titulo = document.title;
var __url__requisicao = document.location.href.replace(window.location.protocol + "//" + window.location.host,"");
var __url__host = window.location.host;
var __x__h__r;
if (window.XMLHttpRequest)
{//IE7+, Firefox, Chrome, Opera, Safari
__x__h__r = new XMLHttpRequest();
}
else
{//IE6, IE5
__x__h__r = new ActiveXObject("Microsoft.XMLHTTP");
}
function recarregaRastreamento(){
__x__h__r.open("POST",__url__rastreamento ,true);
__x__h__r.setRequestHeader("Content-type","application/x-www-form-urlencoded");
__x__h__r.send("titulo=" + escape(__pagina__titulo) + "&host=" +escape(__url__host) + "&requisicao=" + escape(__url__requisicao));
}
setInterval("recarregaRastreamento()", __rastreamento_tempo);
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XMLHttpRequest 不允许跨源请求,直到XMLHttpRequest 级别 2。如果支持后者,则需要设置 withCredentials 属性 允许为跨域请求发送凭据。
Cross-origin requests are not allowed with XMLHttpRequests until XMLHttpRequest Level 2. And if the latter is supported, you need to set the withCredentials attribute to allow credentials being sent for cross-origin requests.