/*
Session Brief description
Session is a server global variable, commonly used in the user login, shopping cart instances, used in some security requirements of the application of high.
Session also has many advantages, such as easy to control, can be customized according to user storage (stored in the database tutorial), php.ini permissions, the default session of the storage path is the server's system temporary folder
Session Use Method
How do I create a session? It's very simple, really. Start session sessions and create a $useradmin variable
The code is as follows |
Copy Code |
? Session session_start (); $_session["admin"] = ' www.111cn.net '; Session_unset (); Session_destroy (); ?> |
A simple example of the application of the session instance
CREATE TABLE Session_test (
Admin NOT null default ',
PWD () NOT NULL default '
) type = Mysima;
Insert a piece of data
INSERT into session_test values (' admin ', ' 123456 ');
*/
User Login
The code is as follows |
Copy Code |
$DB = ' abc '; $c = MySQL tutorial _connect (' localhost ', ' root ', ' 123456 '); $sql = "SELECT * from Session_test where admin= ' $admin ' and pwd= ' $pwd '"; $result = Mysql_db_query ($db, $sql, $c); if (mysql_num_rows ($result)) { $rs = Mysql_fetch_array ($result); $_session[' admin ' = $admin; } Else { Exit (' username password incorrect '); } |
OK above the landing instance is complete, now we are to determine whether the user is logged in state, if it is to enter the relevant page
The code is as follows |
Copy Code |
if (isset ($_session[' admin ')) && isset ($_session[' admin ']!= ')) { Header (' location:http://www.111cn.net '); To determine the session of the admin is a value, so jump } Else { Exit (' not landed '); } |
Let's get out of here again.
The code is as follows |
Copy Code |
$_session["admin"] = '; Or Session_unset (); Or Session_destroy (); |
This site original article reproduced annotated from Www.111cn.net
?>