PHP Exercise Program Notes Cookies

Source: Internet
Author: User
The main point is to set up cookies when logging in and exiting. To save logins and secure exits

1: Setup on login page

Set the value of the cookie
_setcookies ($_rows[' tg_username '), $_rows[' tg_uniqid '],$_clean[' time ']);
_location (null, ' index.php ');

Step two: Generate Cookies,

/** * _setcookies * @param unknown $_username * @param unknown $_uniqid*/function_setcookies ($_username,$_uniqid,$_time){    Setcookie(' username ',$_username); Setcookie(' Uniqid ',$_uniqid); Switch($_time) {         Case' 0 '://Set Browser ProcessSetcookie(' username ',$_username ); Setcookie(' Uniqid ',$_uniqid );  Break;  Case' 1 '://the process of the daySetcookie(' username ',$_username,$_time() + 86400 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 86400 );  Break;  Case' 2 '://a week of progressSetcookie(' username ',$_username,$_time() + 604800 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 604800 );  Break;  Case' 0 '://one-month processSetcookie(' username ',$_username,$_time() + 2592000 ); Setcookie(' Uniqid ',$_uniqid,$_time() + 2592000 );  Break; }}

Step three: Set up in the login state

// login situation is to prevent login after login by direct connection in the browser function _login_state () {    if (!  Isset($_cookie[' username '])) {        _alert_back ("login status cannot be done on this operation! ");    }}

// Delete Cookies function _unsetcookies () {    setcookie(' username ', ', Time()-1);     Setcookie (' Uniqid ', ', Time()-1);    _session_destroy (); // Delete Session    _location (null// do jump }

The fourth step in the login page and exit page Plus

// Login Status    _login_state ();

The above describes the PHP exercise project notes of the cookies, including the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.