PHP exercise project notes COOKIES, php exercise cookies
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 ();
Two ways to display data: Configure in the Data configuration file, my is mysql. func. php
/*** _ Fetch_array can only obtain one Data Group * @ param $ _ SQL */function _ fetch_array ($ _ SQL) {return mysql_fetch_array (_ query ($ _ SQL ), MYSQL_ASSOC);}/*** _ fetch_array_list can return all data of the specified dataset * @ param unknown $ _ result * @ return multitype: */function _ fetch_array_list ($ _ result) {return mysql_fetch_array ($ _ result, MYSQL_ASSOC );}
Finally, assign a value to the page.
// Extract data from the database to obtain the result set // We must re-read the result set each time instead of executing the SQL statement. $ _ Result = _ query ("SELECT tg_username, tg_sex, tg_face FROM tg_user order by tg_reg_time DESC"); <? Php while (!! $ _ Rows = _ fetch_array_list ($ _ result) {?> <Dl> <dd class = "user"> <? Php echo $ _ rows ['tg _ username']?> <? Php echo $ _ rows ['tg _ sex']?> </Dd> <dt> "Alt =" "/> </dt>