Keyword: PHP Session login Verification
This address: http://www.cnblogs.com/txw1958/p/php-login-check-session.html
First, create the Administrator account form in the MySQL database
Create Table Char(8notnullChar(8 not Nullint,primarykey(username));
The table is then initialized and the data is entered.
Insert into Values ('admin','admin123',1);
User Login page:
<HTML> <Head> <title>Login_fangbei</title> </Head> <Body> <formname= "Fangbei"Method= "POST"Action= "check_session_login.php"> <Divstyle= "width:353"> <DL> <DT></DT> <DD> <DivAlign= "Left">Username:<inputtype= "text"name= "username" /> </Div> </DD> <DD> <DivAlign= "Left">Psssword:<inputtype= "Password"name= "Passcode" /> </Div> </DD> <DD> <PAlign= "Center"> <inputtype= "Submit"name= "Submit"value= "Submit" /> <inputtype= "Reset"name= "Reset"value= "Reset" /> </P> </DD> </DL> </Div> </form> </Body></HTML>
Once this page is logged in, it will turn to the check_session_login.php page from the form.
The code is as follows:
<?php@mysql_connect("localhost", "root", ' root ') or die("Database connection Failed");@mysql_select_db("MyDB") or die("Select Database Failed");//get the input information$username=$_post[' username '];$passcode=$_post[' Passcode '];//get the value of Session$query= @mysql_query("Select Username,userflag from users where username = '$username' and passcode = '$passcode‘") or die("SQL statement execution failed");//determine the user and passwordif($row=Mysql_fetch_array($query)){ Session_Start(); //Judging Permissions if($row[' userflag '] = = 1 or$row[' userflag '] = = 0){ $_session[' username '] =$row[' username ']; $_session[' userflag '] =$row[' Userflag ']; Echo"<a href= ' welcome_session_login.php ' > Welcome to Visit Www.cnblogs.com/txw1958</a>"; }Else{ Echo"Userflag not correct"; }}Else{ Echo"Username or Usercode";}?>
After the validation is passed, the Welcome page welcome_session_login.php is reached.
The code is as follows:
<?PHPSession_Start();if(isset($_session[' username '])){ if($_session[' userflag '] = = 1) Echo"Welcome administrator".$_session[' username ']. " Landing; if($_session[' userflag '] = = 0) Echo"Welcome user".$_session[' username ']. " Landing;}Else{ Echo"You do not have permission to access this page";}?>
Finally, there is a destruction session page destroy_session_login.php.
The code is as follows:
<? PHP unset ($_session[' username ']); unset ($_session[' passcode ']); unset ($_session[' Userflag ']); Echo "Logout Success";? >
PHP Login Session Verification