PHP Create and use session cookie variable _php tutorial

Source: Internet
Author: User
Tags session id
Session Start
Session_Start (); Start a session, if you want to use the session program, you must add this sentence
$_session[' user_id ' = ' 123 ';//Assign a value to a SESSION variable if the variable does not exist to create

echo $_session[' user_id '];//access SESSION variable

$_session = Array ();//clears 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 work variables

Setcookie (' user_id ', 0,time ()-1);//Delete cookie variable
Codie End

This code is not run, just use all the methods listed here, the actual should be different features on different pages to use, will be shown in the following example
?>
Session Start
Session_Start (); Start a session, if you want to use the session program, you must add this sentence
$_session[' user_id ' = ' 123 ';//Assign a value to a SESSION variable if the variable does not exist to create

echo $_session[' user_id '];//access SESSION variable

$_session = Array ();//clears 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 work variables

Setcookie (' user_id ', 0,time ()-1);//Delete cookie variable
Codie End

This code is not run, just use all the methods listed here, the actual should be different features on different pages to use, will be shown in the following example
?>
Cookie,session is a way for Web applications to maintain user state

A cookie is information that is stored by the client and sent to the server when the client connects to the server.

Session is stored on the server side of the information, from this point of view session relative cookie more secure
When the session is created, the server returns an encrypted session ID to the client to identify the user, and the session ID is generally stored in the cookie when the cookie is not available by URL

The above code shows how to create and use session cookie variables

http://www.bkjia.com/PHPjc/364050.html www.bkjia.com true http://www.bkjia.com/PHPjc/364050.html techarticle ? PHP//Session start Session_Start ();//Start a session, if you want to use the session program first must add this sentence $_session[' user_id '] = ' 123 ';//Give a session Variable Assignment ...

  • Related Article

    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.