COOKIES for PHP exercise project notes

Source: Internet
Author: User
: 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.

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.