<?php
Session Start
Session_Start (); To start a session, if you want to use the sessions program, you must add this sentence to the front
$_session[' user_id '] = ' 123′;//assigns a value to a session variable that is created if the variable does not exist
echo $_session[' user_id '];//access session variable
$_session = Array ();//Empty all session variables
Session_destroy ()//purge session ID
Session End
Cookie Start
Setcookie (' user_id ', 123);//Create a cookie variable user_id=123
echo $_cookie[' user_id '];//access to COOKIE variables and workaround variables
Setcookie (' user_id ', 0,time ()-1);//Delete cookie variable
Codie End
The code is not running, just listing all the usage methods here, and actually using different features on different pages, will demonstrate in the following example
?>
<?php
Session Start
Session_Start (); To start a session, if you want to use the sessions program, you must add this sentence to the front
$_session[' user_id '] = ' 123′;//assigns a value to a session variable that is created if the variable does not exist
echo $_session[' user_id '];//access session variable
$_session = Array ();//Empty all session variables
Session_destroy ()//purge session ID
Session End
Cookie Start
Setcookie (' user_id ', 123);//Create a cookie variable user_id=123
echo $_cookie[' user_id '];//access to COOKIE variables and workaround variables
Setcookie (' user_id ', 0,time ()-1);//Delete cookie variable
Codie End
The code is not running, just listing all the usage methods here, and actually using different features on different pages, will demonstrate in the following example
?>
Cookie,session is a way for Web applications to maintain user state
Cookies are information stored by the client that is sent to the server when the client connects to the server.
Session is stored on the server side of the information, from this angle session relative to the cookie more secure
When the session is created, the server returns to the client a cryptographic session ID to identify the user, which is generally stored in a cookie that is passed by the URL when the cookie is not available
The above code shows how to create and use session cookie variables