请问各位大侠,session登录验证是什么意思。怎么实现?

解决方案 »

  1.   

    <?php 
    session_start();
    echo $_SESSION['msg']; 
    ?>
    <html>
    <head>
    </head>
    <body>
    <form method="POST" action="login.php" name="send" onsubmit="return ChkFields()"><p align="center">用户名:&nbsp;<input type="text" name="Username"><a href=zhuce.php>注册用户</a></p>
    <p align="center">密&nbsp;码:&nbsp;<input type="password" name="Pwd"><a href=findpwd.php>忘记密码?</a></p>
    <p align="center"><input type="submit" value="登陆" name="a1"><input type="reset" value="重写" name="b2"></p></form><script language="javascript">
    function ChkFields(){
    if(document.send.Username.value==""){
       window.alert("请输入姓名")
       return false
    }
    if(document.send.Pwd.value==""){
       window.alert("请输入密码")
       return false
    }
    return true
    }
    </script>
    </body>
    </html>
    登录处理<?php
    session_start();
    $submit=$_POST["a1"];
    $username=$_POST["Username"];
    $pwd=$_POST["Pwd"];
    if($submit=="登陆")
    {
    $conn=mysqli_connect("localhost","root","root","user");
    if(empty($conn))
    {
       die("数据库连接失败");
    }
    else
    {   $conn->query('set names gb2312');
       $str="select * from user where 用户名='".$username."'and 密码='".$pwd."'";
       $result=$conn->query($str);
       $row=$result->fetch_row();
        if($row)
       {
       
        $_SESSION["Username"]=$username;
        $_SESSION["Passed"]=True;
        echo "<script>window.location.href='login_ok.php'</script>";
       }
          else
           {
           $msg="用户名或密码错误";
           $_SESSION['msg']=$msg;
          echo "<script>window.location.href='login1.php'</script>";
           }

    }
    ?>登录成功<?php
    session_start();
    include('login.php');
    ?>
    <head>
    </head>>
    <h2 align="center">用户管理</h2>>
    <hr>
    <center>
    <script language="javascript">
    function newwin(url)
    {
    var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=380");
    newwin.focus();
    return false;
    }
    </script>
    <?php
    if(isset($_SESSION["Passed"]))
    {
    echo $_SESSION["Username"].";欢迎回来"."\n";
    echo "<a href=Pwdchange.php?username=" . $_SESSION["username"] . "onclick='return newwin(this.href)'>修改密码</a><a href=loginout.php>退出登陆</a>";
    }
    ?>
    注销<?php
         $_SESSION["Passed"]=false;
         $_SESSION["Username"]="";
         
         $_SESSION['msg']="";
         header("Location:login1.php");
         
    ?>
    试试