This article mainly introduces the related information about the example of using COOKIES in PHP. For more information, see setting cookies when logging on and exiting. 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) {?>
-
<? Php echo $ _ rows ['tg _ username']?> <? Php echo $ _ rows ['tg _ sex']?>
-
"Alt =" "/>
The above is all the content of this article. I hope you will like it.