: This article mainly introduces COOKIES for PHP exercise project notes. For more information about PHP tutorials, see. Cookies are set during login and exit. To save logon and exit
1: Set on the logon page
// Set the cookie value
_ Setcookies ($ _ rows ['tg _ username'], $ _ rows ['tg _ uniqid'], $ _ clean ['Time']);
_ Location (null, 'index. php ');
Step 2: generate a cookie,
/*** _ Setcookies * @ param unknown $ _ username * @ param unknown $ _ uniqid */function _ setcookies ($ _ username, $ _ uniqid, $ _ time) {setcookie ('username', $ _ username); setcookie ('uniqid', $ _ uniqid); switch ($ _ time) {case '0 ': // Set the browser process setcookie ('username', $ _ username); setcookie ('uniqid', $ _ uniqid); break; case '1 ': // one-day process setcookie ('username', $ _ username, $ _ time () + 86400); setcookie ('uniqid', $ _ uniqid, $ _ time () + 86400); break; case '2': // one-week process setcookie ('username', $ _ username, $ _ time () + 604800 ); setcookie ('uniqid', $ _ uniqid, $ _ time () + 604800); break; case '0': // setcookie ('username ', $ _ username, $ _ time () + 2592000); setcookie ('uniqid', $ _ uniqid, $ _ time () + 2592000); break ;}}
Step 3: Set in logon status
// When logging on, it is prevented from logging on to function _ login_state () {if (! Isset ($ _ COOKIE ['username']) {_ alert_back ("The logon status cannot be changed! ");}}
// Delete cookiesfunction _ unsetcookies () {setcookie ('username', '', time ()-1); setcookie ('uniqid','', time () -1); _ session_destroy (); // delete session _ location (null, 'index. php '); // jump}
Step 4 add
// Logon status _ login_state ();
The above introduces the COOKIES of PHP exercise project notes, including some content, and hopes to help friends who are interested in PHP tutorials.