I'm running the following javascript that check with serverside (keep.php) if user has a session. The script is running onload of every page: handler.js
var server = location.host;
var url = "http://" + server + "/MyHome2/php/";
var page = "keep.php";
document.onload = checkAuth();
function checkAuth()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
if (response != "")
{
document.getElementById("linkSign").innerHTML = response + "|" ;
}
else
document.getElementById("linkSign").innerHTML = "Sign-in|" ;
}
}
xmlhttp.open("POST",url + page,true);
xmlhttp.send();}
My server-side keep.php which echo back session is:
<?php
session_start();
if (isset($_SESSION['name']))
{
echo $_SESSION['name'];
}
?>
This script is running in the begging of each html page to check if user has a session and if it does it grrets him. The problem that this script is messing with my other scripts! that used to work and are working without this handler.js
For example my login script which log-in a user is not working when user try to submit his credentials, noting happens!
var server = location.host;
var url = "http://" + server + "/MyHome2/php/";
var urlmain = "http://" + server + "/MyHome2/index.html";
var page = "authentication.php";
function loginUser(){
var str = "usr=" + encodeURIComponent(document.getElementById("user").value) + "&pwd=" + encodeURIComponent(document.getElementById("password").value);
checkUserExistance(str,str.length);}
function checkUserExistance(data,size){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response = xmlhttp.responseText;
responseHandler(response);
}
}
xmlhttp.open("POST",url + page,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",size);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(data);}
Why is the simple session check onload of each page is preventing mt other script from executing?!