PHP简易用户登录模板

只是个示例,没有用户名输入且只能用唯一的密码登录,拿来用的话还是要狂改一下的。

<?php if($_GET[‘action’]==””){ ?>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>PHP登录模板</title>
</head>
<body>
<br />
<?php
}
if($_GET[‘action’]==”login”)
{
$IPAddr=GetRealIPAddr();
if($_POST[‘pw’]==”123456″&&$IPAddr!=””)
{
$loginTime=time();
setcookie(“login_time”,$loginTime);
setcookie(“login_ip_addr”,$IPAddr);
setcookie(“login_check”,md5(“!!!xiaoxixi”.$loginTime.$IPAddr.”fucku!!!”));
header(“Location: http://”.$_SERVER[‘HTTP_HOST’].”/”);
}
else
{
?>
<br />
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<p align=”center”><font color=”#FF0000″ >登录失败!</font><a href=”/”>返回</a></p>
<?php
}
}
else if($_GET[‘action’]==”logout”)
{
setcookie(“login_time”,””);
setcookie(“login_ip_addr”,””);
setcookie(“login_check”,””);
header(“Location: http://”.$_SERVER[‘HTTP_HOST’].”/”);
}
else if(IsLogin())
{
?>
<p align=”center”>您现已成功登录。本次登录将在<font color=”#FF0000″><?php echo date(“Y年m月d日H时i分s秒”,$_COOKIE[‘login_time’]+86400); ?></font>自动失效。<a href=”/?action=logout”>退出登录</a></p>
<?php
}
else
{
?>
<div align=”center”>
<table width=”307″ height=”103″ border=”1″>
<tr>
<td height=”23″><div align=”center” class=”STYLE1″>Enter the Backstage Password </div></td>
</tr>
<tr>
<td height=”59″>
<form action=”/?action=login” method=”post”>
<div align=”center”>
<input type=”password” name=”pw” />
<input type=”submit” name=”button” value=”提交” />
</div>
</form>
</td>
</tr>
</table>
</div>
<?php
}

function IsLogin()
{
if((time()-$_COOKIE[‘login_time’]>86400)||($_COOKIE[‘login_ip_addr’]!=GetRealIPAddr())||($_COOKIE[‘login_check’]!=md5(“!!!xiaoxixi”.$_COOKIE[‘login_time’].$_COOKIE[‘login_ip_addr’].”fucku!!!”)))
{
return false;
}
return true;
}

function GetRealIPAddr()
{
if (!empty($_SERVER[‘HTTP_CLIENT_IP’]))
{
$ip=$_SERVER[‘HTTP_CLIENT_IP’];
}
elseif(!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
{
$ip=$_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
else
{
$ip=$_SERVER[‘REMOTE_ADDR’];
}
return $ip;
}
?>
</body>
</html>

在〈PHP简易用户登录模板〉中有 2 則留言

發佈回覆給「匿名訪客」的留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *