Home > php教程 > php手册 > 简化的实现方法(限制为同一会话页面)

简化的实现方法(限制为同一会话页面)

WBOY
Release: 2016-06-21 09:11:51
Original
695 people have browsed it

页面

session_start();
$login=false;

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

if(file_exists($loginFILE)&& (time()-filemtime($loginFILE))        $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 "

可以确定你是独苗苗~:)

";
                    $cf=fopen($loginFILE,"a+");
                    fputs($cf,"\r\na");
                    fclose($cf);//这里增加文件记录仅仅是为了修改文件的最后修改时间
                    echo "";//消除刷新页面浏览器提示
                }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 "";//刷新页面使用转变后变量进行验证
            }else{
                $outtime=time()-filemtime($loginFILE)-60;
                echo "登陆不存在或您已经超时(".$outtime."秒)...";
            }
}
if(!$login){
?>
    

        
        

        用户名:


        
密码:

        
 
        

    


}
?>


t.php
=====



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template