先创建一个index.php脚本文件,其代码如下:
<form name="addForm" method="post" action="check.php">
<h2>用户登录</h2>
用户名:<input type="text" name="uname"><br>
密 码:<input type="password" name="keyword"><br>
<tr>
<input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置">
</tr>
</form>
然后创建一个check.php的文件,其代码如下:
if(isset($_POST['submit'])&&$_POST['submit'])
{
if($_POST['uname']=="admin"&&$_POST['keyword']=="admin")
echo "登录成功";
else
{
$url="index.php";
echo "<script language='javascript' type='text/javascript'>";
echo "alert('请输入正确的用户名和密码')";
echo "</script>";
echo "<script language='javascript' type='text/javascript'>";
echo "window.location.href='$url'";
echo "</script>";
}
}
效果图如下: