Objective to determine whether a redirect is achieved by controlling whether or not a value in the cookie
HTTP mode
<?php
if ($_cookie[' test '] = = 1) {
Echo ' has cookie test ';
unset ($_cookie[' test ');
Setcookie (' Test ', ', Time ()-360000, '/');
unset ($_cookie[' test ');
Header (' location:/http/test.php ');
} else {
Setcookie (' Test ', 1, time () + 3600, '/');
Echo ' Set cookie ';
}
JS mode
Window.onload = function () {
Alert (GetCookie (' Test '));
ClearCookie (' Test ');
window.location = "/http/test.php";
}
function Setcookie (CNAME, cvalue, exdays) {
var d = new Date ();
D.settime (D.gettime () + (exdays*24*60*60*1000));
var expires = "expires=" +d.toutcstring ();
Document.cookie = cname + "=" + Cvalue + ";" + Expires + "; path=/"; #注意cookie的域 default is the current path
}
Clearing cookies
function ClearCookie (name) {
Setcookie (Name, "",-1000);
}
Get cookies
function GetCookie (CNAME) {
var name = cname + "=";
var ca = Document.cookie.split (';');
for (var i=0; i<ca.length; i++) {
var c = Ca[i];
while (C.charat (0) = = ") c = c.substring (1);
if (C.indexof (name)! =-1) return c.substring (Name.length, c.length);
}
Return "";
}
</script> ';
PHP,JS Clearing Cookies