-
Notifications
You must be signed in to change notification settings - Fork 1
/
cookie_check_logout.js
74 lines (67 loc) · 1.8 KB
/
cookie_check_logout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
1.This script checks if the user is already logged in.
2.using AJAX runs the file mismatch_login_check.php file and passes an argument 'a=check' to it.
3.getinf():-This function recieves the response of mismatch_login_check.php in variable 'val' and calls the function loginInfo();
4.loginInfo():-This function takes actions on the basis of the value of 'val' i.e. response from mismatch_login_check.php.
5.logout():-This function again calls the mismatch_login_check.php file with different value of 'a' and deletes the cookie(logout the user) and calls function delInf().
6.delInf():-This function checks the response of mismatch_login_check.php and calls afterLogout().
7.afterLogout():-This functions takes the action on logout i.e hiding and showing different elements.
*/
var req;
var req1;
var val;
var url="mismatch_login_check.php?a=check";
if(window.XMLHttpRequest){
req=new XMLHttpRequest();
}
else if(window.ActiveXObject){
req=new ActiveXObject("Microsoft.XMLHTTP");
}
try{
req.onreadystatechange=getInf;
req.open("GET",url,true);
req.send();
}catch(e){
alert("Can't connect to server");
}
function getInf()
{
if(req.readyState==4)
{
window.val=req.responseText;
loginInfo();
req.abort();
}
}
function loginInfo()
{
if(window.val!='No')
{
var prof=document.getElementById('profile-button');
prof.innerHTML=val;
}
}
function logout()
{
url="mismatch_login_check.php?a=delcookie&b="+val;
try{
req.onreadystatechange=delInf;
req.open("GET",url,true);
req.send();
}catch(e){
alert("Can't connect to server");
}
}
function delInf()
{
if(req.readyState==4)
{
afterLogout();
req.abort();
window.location='mismatch_homepage.php';
}
}
function afterLogout()
{
document.getElementById('password').value="";
}