COOKIES for PHP exercise project notes, cookies_PHP tutorial for php exercises

Source: Internet
Author: User
COOKIES for PHP exercise project notes, and cookies for php exercises. COOKIES for PHP exercise project notes. php exercise cookies are mainly set when you log on and exit. To save logon and secure exit 1: On the logon page, set the cookie value for PHP exercise project notes, and set 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 ");
     
 
 
$ _ Rows ['tg _ face']?> "Alt =" "/>

Tokens are used to set cookies during logon and exit. To save login and secure exit 1: on the login page, set // Set the cookie value...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.