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

页面

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
=====



Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor