Basic knowledge of PHP session control

Source: Internet
Author: User
Tags php session setcookie

Cookies

//Set Cookies$uid= "Admin";$pwd= 123;Setcookie("UID",$uid, Time() +24*60*60);//The variable is stored in a cookie, the first parameter variable name (string), the second parameter variable value (can also be directly written value), and the third is the deposit time (not written by default when the browser is closed)Setcookie("pwd",$pwd, Time() +24*60*60);//Delete CookiesSetcookie("pwd", "", Time()-1);//also use this function, just change the time to the time before now

Session

//setting Session//session_start () cannot have any output in front of it, this function sends a SESSION_ID presence cookie to the client and establishes a session text file on the server side and saved in the cookie scheduling PHP mechanism using sessionSession_Start();//using the $_session array$_session[' uid ']= ' admin ';$_session[' Age ']=18;Print_r($_session);//output Session Global arrayEcho Session_name()." =".session_id();//Show session name&id//clear SESSION//1. Use unset to delete eachunset($_session[' UID ']);//2. Delete all the contents of the array$_session=Array();//3. Delete the SessionID in the customer cookieif(isset($_cookie[Session_name()]))//prevent the deletion of the mistake and judge it beforehand{ Setcookie(Session_name(),"", Time()-1, "/");}//4. Destroy the session, delete the user on the server side of the fileSession_destroy();

Basic knowledge of PHP session control

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.