mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-14 09:11:34 +01:00
47 lines
1.3 KiB
JavaScript
Executable File
47 lines
1.3 KiB
JavaScript
Executable File
var script = document.currentScript; //For know path
|
|
|
|
//Returns path of file, without /
|
|
function cutUrlFile(cad){
|
|
chars = cadena.split("");
|
|
blocks = cadena.split("/");
|
|
blockNum=1;
|
|
|
|
if(chars[chars.length-1]==="/"){
|
|
blockNum++;
|
|
}
|
|
|
|
pseudoReturn = [];
|
|
|
|
for(i=0;i<blocks.length-blockNum;i++){
|
|
pseudoReturn.push(blocks[i]);
|
|
}
|
|
|
|
return pseudoReturn.join("/");
|
|
}
|
|
|
|
var path = cutUrlFile(script.src); //Path, for calling php in Ajax
|
|
|
|
function loadcounter() { //Todo el js
|
|
var cookiename = "CheckWeb" + SiteID;
|
|
var b = document.cookie.match('(^|;)\\s*' + cookiename + '\\s*=\\s*([^;]+)');
|
|
var iscookie = b ? b.pop() : '';
|
|
if (iscookie != ""){
|
|
var visited = 1; //Visitado
|
|
}else{ //Si no esta visitado, hacer la cookie y contar visita unica
|
|
var visited = 0;
|
|
var d = new Date();
|
|
d.setTime(d.getTime() + (24*3600*1000));
|
|
var expires = "expires="+ d.toUTCString();
|
|
document.cookie = "CheckWeb" + SiteID + "=visited" + "; " + expires;
|
|
}
|
|
// Enviamos los datos para introducir en la DB
|
|
// Obtener la instancia del objeto XMLHttpRequest
|
|
conexion = new XMLHttpRequest();
|
|
// Realizar peticion HTTP
|
|
conexion.open('POST', path+'/counterajax.php');
|
|
conexion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
conexion.send("SiteID="+SiteID+"&visited="+visited);
|
|
}
|
|
|
|
loadcounter(); //Para que funcione
|