Knowledge Points:
Session is the server will be generated from the Web page of the information in an array into a PHP file, the resulting global variables, you can call this data in other pages under the system.
Cookies are similar to the session principle, but they are stored to the user's computer, not to the server.
Function:
Session_Start (); PHP script to open the session function, it is recommended to write in the first line of PHP.
SESSION assignment: $_session[' id '] = 1;
Session detects if the variable is registered: session_is_registered (' id '), returns TRUE or false; Can be equated to isset ($_session[' id ');
Session Destruction: Session_unset (), no parameters, no return value, equivalent to Session_destroy ();
SESSION single-Variable Destruction: unset ($_session[' id '));
Setcookie (Name,value,lifetime,path,domain): Name is the index name of the cookie, value is the cookie, the lifetime time to live, the path cookie holds the address, domain Store the domain name.
Code:
<?php
Session_Start ();
$_session[' name '] = "name";
echo $_session[' name '];//output name
if (session_is_registered (' name ') ===false) {
This variable was not found in echo ' Session! ';
}else{
This variable exists in echo ' Session! ‘;
}
Setcookie (' name ', $_session[' name '],time () +3600);//Set Cookie to live for one hour
echo $_cookie[' name '];//output name
unset ($_session[' name ');//Delete SESSION variable
Session_destroy ();
?>
Page Tip:
PHP Session and Cookie