<?php
Header (' Content-type:text/html;charset=utf-8 ');
if (!empty ($_post)) {
$name = $_post[' name '];
$PSW = $_post[' PSW '];
if ($name = = ' Jack ' && $psw = = ' Rose ') {
Echo 1;
Exit
} else {
echo 0;
Exit
}
}
?>
<title>testCookie</title>
<body>
<form action= "/testtest.php" >
Name:<input class= "name" name= "name" type= "text"/><br>
PSW: <input class= "PSW" name= "PSW" type= "password"/><br>
Sub:<button class= "btn" onclick= "return sub ()" > Login </button>
</form>
</body>
<script src= "https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/ Jquery-1.10.2.min_f2fb5194.js "type=" Text/javascript "></script>
<script type= "Text/javascript" >
Window.onload = function () {
var is_save_login = GetCookie (' Is_save_login ');
if (is_save_login== ' yes ') {
var name = GetCookie (' Name_login ');
var PSW = GetCookie (' Psw_login ');
if (name && PSW) {
$ ('. Name '). Val (name);
$ ('. PSW '). Val (PSW);
$ ('. BTN '). HTML (' automatic login ');
$.post ('/testcookie.php ', {' name ': Name, ' PSW ':p SW}, Function (res) {
if (res== ' 1 ') {
Addcookie (' Is_save_login ', ' yes ', 7x24);
Addcookie (' Name_login ', name, 7x24);
Addcookie (' Psw_login ', PSW, 7x24);
Alert (' Automatic login successful! ‘);
window.location.href = ' http://www.mljun.com ';
} else {
Alert (' Automatic login failed! ‘);
$ ('. PSW '). Val (');
}
})
} else {
Deletecookie (' Is_save_login ');
Deletecookie (' Name_login ');
Deletecookie (' Psw_login ');
}
}
Delete Cookies
function Deletecookie (name) {
var date=new date ();
Date.settime (Date.gettime ()-10000);
Document.cookie=name+ "=V; Expire= "+date.togmtstring ();
}
Get cookies
function GetCookie (name) {
var Strcookie=document.cookie;
var arrcookie=strcookie.split (";");
for (Var i=0;i<arrcookie.length;i++) {
var arr=arrcookie[i].split ("=");
if (Arr[0]==name) return arr[1];
}
Return "";
}
}
Submit
function sub () {
var name = $ ('. Name '). Val ();
var PSW = $ ('. PSW '). Val ();
$.post ('/testcookie.php ', {' name ': Name, ' PSW ':p SW}, Function (res) {
if (res=== ' 1 ') {
Addcookie (' Is_save_login ', ' yes ', 7x24);
Addcookie (' Name_login ', name, 7x24);
Addcookie (' Psw_login ', PSW, 7x24);
Alert (' Login successful! ‘);
window.location.href = ' http://www.mljun.com ';
} else {
Alert (' Login failed! ‘);
$ ('. PSW '). Val (');
}
})
return false;
}
Set cookies
function Addcookie (name,value,expirehours) {
var cookiestring=name+ "=" +escape (value);
Determine if the expiration time is set
if (expirehours>0) {
var date=new date ();
Date.settime (date.gettime+expirehours*3600*1000);
Cookiestring=cookiestring+ "; Expire= "+date.togmtstring ();
}
document.cookie=cookiestring;
}
</script>
Cookies enable users to log in automatically