欢迎光临
我们一直在努力

简化的实现方法(限制为同一会话页面)-PHP教程,PHP应用

建站超值云服务器,限时71元/月

<?php
session_start();
$login=false;

$lifetime=60;//会话时间
$loginfile="loginmsg.txt";

if(file_exists($loginfile)&& (time()-filemtime($loginfile))<$lifetime){//在会话时间范围内
        $info=file($loginfile);
            $username=trim($info[0]);    //已在线的登陆用户名
            $password=trim($info[1]);    //已在线密码(可以不保存)
            $ip     =trim($info[2]);    //已在线ip
            $sid     =trim($info[3]);    //已在线port
            if(strcmp($_session[loginuser],$username)==0){
                if(strcmp($_session[loginpw],$password)==0){
                    $login=true;
                    echo "<h3>可以确定你是独苗苗~:)</h3>";
                    $cf=fopen($loginfile,"a+");
                    fputs($cf,"\r\na");
                    fclose($cf);//这里增加文件记录仅仅是为了修改文件的最后修改时间
                    echo "<meta http-equiv=refresh content=\"10;url=t.php\">";//消除刷新页面浏览器提示
                }else{
                    echo "密码错误";
                }
            }else{
                echo "已经有用户($username)登陆系统,但那人不是你:),你还是等会再登陆吧…暂时不允许登陆";
                print_r($_session);
            }
}else{//用户超时,或根本没登陆系统、或为登陆系统进行必要的变量转换
            if(isset($_post[loginuser])){
                $_session[loginuser]=$_post[loginuser];    //转变形式
                $_session[loginpw]=$_post[loginpw];
                $fp=fopen($loginfile,"w");    //清除所有旧的登陆信息
                $msg=$_post[loginuser]."\r\n".$_post[loginpw]."\r\n";
                fwrite($fp,$msg);
                fclose($fp);
                $login=flase;    //禁止登陆页面显示
                echo "<meta http-equiv=refresh content=\"0;url=index.php\">";//刷新页面使用转变后变量进行验证
            }else{
                $outtime=time()-filemtime($loginfile)-60;
                echo "登陆不存在或您已经超时(".$outtime."秒)…";
            }
}
if(!$login){
?>
    <form action="<?=$_server[php_self]?>" method="post" name="loginform">
        <table cellpadding=0 border=0>
        <tr><td>
        用户名:<td><input type="text" name="loginuser"></span><br>
        <tr><td>密码:<td><input type="password" name="loginpw"></span><br>
        <tr><td> <td><input type="button" value=" login " onclick="if(this.form.loginuser.length*this.form.loginpw.length!=0){this.form.submit();}else{return false;}">
        </table>
    </form>
<?
}
?>

t.php
=====
<meta http-equiv=refresh content="0;url=<?=$_server[http_referer]?>">

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 简化的实现方法(限制为同一会话页面)-PHP教程,PHP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章