开发者

XMLHttpRequest and Unique Session ID PHP

开发者 https://www.devze.com 2023-04-05 18:07 出处:网络
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

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 onl开发者_JAVA技巧ine.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消