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.
精彩评论