<?php ob_start();?>
<?php include_once("Welcome.php"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
</style>
<?php
function check($name,$key){
$str1=range(0,9);
$str2=range(A,z);
$str3=implode("",$str1).implode("",$str2);
if(strlen($name)<4){
echo "账号过短(至少4位)";
return false;
}
else if(strlen($key)<6){
echo "密码过短(至少六位)";
return false;
}
else if((strspn($name,$str3)!=strlen($name))){
echo "账号不能含有特殊字符";
return false;
}
else if((strspn($key,$str3)!=strlen($key)))
{
echo "密码不能含有特殊字符";
return false;
}
else return true;
}
?>
</head>
<?php
if (isset($_COOKIE['username']) && $_COOKIE['username']) {
echo "<p align='center'>您已登录</p>";
echo "<p align='center'><a href='board.php'>留言板</a><p>";
exit;
}
if($_SERVER['REQUEST_METHOD']=='GET') { ?>
<form action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post">
<table border="3" bgcolor="#99CCCC" align="center">
<tr>
<td>账号:</td>
<td>
<input type="text" name="username"/>
</td>
<tr>
<td>密码:</td>
<td>
<input type="password" name="userkey"/>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="登录"/>
</td>
</tr>
</table>
</form>
<?php }
else{
if(check($_POST['username'],$_POST['userkey']))
{
include_once("sql.php");
if(PiPei1($_POST['username'],$_POST['userkey']))
{
setcookie("username", $_POST['username'], time() + 3600);
echo "<p align='center'>登录成功</p>";
echo "<p align='center'><a href='board.php'>留言板</a><p>";
$flag=1;
}
else echo "登录失败,请检查用户名和密码。";
}
}
?>
</html>
- 1
- 2
- 3
前往页