Simplified implementation (limited to the same session page)

Source: Internet
Author: User
Tags strcmp trim
Page <?php
Session_Start ();
$login =false;

$lifetime =60;//Session Time
$loginFILE = "Loginmsg.txt";

if (file_exists ($loginFILE) && (Time ()-filemtime ($loginFILE)) < $lifetime) {//in session timeframe
$info =file ($loginFILE);
$username =trim ($info [0]); Logged in User name online
$password =trim ($info [1]); Online password (can not be saved)
$ip =trim ($info [2]); Already online IP
$sid =trim ($info [3]); Already online 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);//Add file records here only to modify the last modification time of the file
echo "<meta http-equiv=refresh content=\" 10;url=t.php\ ">"/Erase Refresh page browser prompt
}else{
echo "Password Error";
}
}else{
echo "already has user ($username) login system, but that person is not you:", you still wait for the landing again ... Not allowed to land temporarily ";
Print_r ($_session);
}
}else{//user timeout, or no login system, or for the landing system to make the necessary variable conversion
if (Isset ($_post[loginuser])) {
$_session[loginuser]=$_post[loginuser]; form of change
$_SESSION[LOGINPW]=$_POST[LOGINPW];
$FP =fopen ($loginFILE, "w"); Clear all old login information
$msg =$_post[' Loginuser ']. " \ r \ n ". $_post[' LOGINPW ']." \ r \ n ";
Fwrite ($fp, $msg);
Fclose ($FP);
$login =flase; No landing page display
echo "<meta http-equiv=refresh content=\" 0;url=index.php\ ">"//Refresh page to validate with transformed variables
}else{
$outtime =time ()-filemtime ($loginFILE)-60;
echo "Login does not exist or you have timed out (". $outtime. " seconds) ... ";
}
}
if (! $login) {
?>
<form action= "<?=$_SERVER[PHP_SELF]?>" method= "post" name= "LoginForm" >
<table cellpadding=0 border=0>
<tr><td>
User name: <td><input type= "text" name= "Loginuser" ></span><br>
<tr><td> Password: <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]?>" >

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.