PHP Login Session Verification

Source: Internet
Author: User
Tags php session

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

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.