PHP Login Session Verification Instance

Source: Internet
Author: User
Interface:

<html><head><title>Login 
     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">Password:<inputtype="password"name="pwd" /> 
     Div
 > 
     DD
 ><dd><pAlign="center"><inputtype="Submit"name="Submit"value ="Submit" /><inputtype="reset"name="reset"value="Reset" /> 
     P
 > 
     DD
 > 
     DL
 > 
     Div
 > 
     Form
 > 
     Body
 > 
     HTML
 >

Database preparation:

Username Pwd Userflag
Perry 123 1

Login Verification:


    Header"content-type:text/html; Charset=utf-8 ");$servername="localhost";$username="Root";$password="";$dbname="Paul.";$conn=NewMysqli ($servername,$username,$password,$dbname);if($conn->connect_error) { die("Connection failed:".$conn->connect_error);}$conn->query ("SET NAMES UTF8");//Get input information$username=$_post[' username '];$pwd=$_post[' pwd '];//Get the value of Session$sql="Select Username,userflag from test_login where username = ' $username ' and pwd = ' $pwd '";$result=$conn->query ($sql);//Judge user and passwordif($result->num_rows >0) {session_start ();//Judge permissions$row=$result->fetch_assoc ();if($row[' Userflag '] ==1or$row[' Userflag '] ==0){$_session[' username '] =$row[' username '];$_session[' Userflag '] =$row[' Userflag '];Echo"Welcome to visit"; }Else{Echo"User of the puzzle"; }}Else{Echo"The user name or password is incorrect";}

Welcome interface:


   
    header("Content-Type: text/html; charset=utf-8");session_start();if(isset($_SESSION['username'])){    if($_SESSION['userflag'] == 1)        echo"欢迎管理员".$_SESSION['username']."登录";    if($_SESSION['userflag'] == 0)        echo"欢迎用户".$_SESSION['username']."登录";}else{    echo"登录已过期";}unset($_SESSION['username']);unset($_SESSION['pwd']);unset($_SESSION['userflag']);echo"
会话结束";

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP login session verification example, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.