The main point is to set up cookies when logging in and exiting. To save logins and secure exits
1: Setup on login page
Set the value of the cookie
_setcookies ($_rows[' tg_username '), $_rows[' tg_uniqid '],$_clean[' time ']);
_location (null, ' index.php ');
Step two: Generate Cookies,
/** * _setcookies * @param unknown $_username * @param unknown $_uniqid*/function_setcookies ($_username,$_uniqid,$_time){ Setcookie(' username ',$_username); Setcookie(' Uniqid ',$_uniqid); Switch($_time) { Case' 0 '://Set Browser ProcessSetcookie(' username ',$_username ); Setcookie(' Uniqid ',$_uniqid ); Break; Case' 1 '://the process of the daySetcookie(' username ',$_username,$_time() + 86400 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 86400 ); Break; Case' 2 '://a week of progressSetcookie(' username ',$_username,$_time() + 604800 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 604800 ); Break; Case' 0 '://one-month processSetcookie(' username ',$_username,$_time() + 2592000 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 2592000 ); Break; }}
Step three: Set up in the login state
// login situation is to prevent login after login by direct connection in the browser function _login_state () { if (! Isset($_cookie[' username '])) { _alert_back ("login status cannot be done on this operation! "); }}
// Delete Cookies function _unsetcookies () { setcookie(' username ', ', Time()-1); Setcookie (' Uniqid ', ', Time()-1); _session_destroy (); // Delete Session _location (null// do jump }
The fourth step in the login page and exit page Plus
// Login Status _login_state ();
The above describes the PHP exercise project notes of the cookies, including the content, I hope the PHP tutorial interested in a friend helpful.