PHP creates and uses session cookie variables

Source: Internet
Author: User
Tags session id sessions setcookie

<?php//Session start Session_Start (); Start a conversation, if you want to use the session program the front must add this sentence $_session[' user_id ' = ' 123′;

Assign a value to a session variable that creates the Echo $_session[' user_id '];//access session variable $_session = array () If the variable does not exist, or empty all session variables Sessi On_destroy ();

Clear session ID

Session End

Cookie start Setcookie (' user_id ', 123);

Create a cookie variable user_id=123 echo $_cookie[' user_id '];//access cookie variables and workaround variables Setcookie (' user_id ', 0,time ()-1);

Delete cookie variable//Codie end//The code is not run, just put all the use methods listed here, the actual should be different features in different pages, will be shown in the following example?>

<?php//Session start Session_Start (); To start a session, if you want to use the sessions program the first must add this sentence $_session[' user_id ' = ' 123′;//to assign a value to an argument, if the variable does not exist, create echo $_session[' us er_id '];//Access session variable $_session = array ();//empty all Session variables Session_destroy ();

Clear session ID

Session End

Cookie start Setcookie (' user_id ', 123);

Create a COOKIE variable user_id=123 echo $_cookie[' user_id '];

Access cookie variables and workaround variables Setcookie (' user_id ', 0,time ()-1);

Delete Cookie Variable

Codie End

         //The code is not operational, just list all the usage methods here, the actual should be different function on different page use, will demonstrate?> cookie,session in the following example is a way for a Web application to keep the state of the user. Cookies are information stored by the client that is sent to the server when the client connects to the server. The session is stored on the server side of the information, from this point of view sessions relative to the cookie is more secure when the conversation is created, the servers return to the client with an encrypted time ID to identify the user, the Generally stored in cookies when a cookie is not available, the code above is passed by the URL to show how to create and use the session cookie variable

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.