<?php
include("config.php");//数据库方面链接
$username=$_POST["youname"];
$pws=$_POST["lovephp_pws"];
if($username=="" or $pws==""){ //如果用户与密码为空那么就提示
echo("<script type='text/javascript'> alert('用户名和密码不能为空!');location.href='admin.php';</script>");
exit;
}
if($username==$youname and $pws==$lovephp_pws){
session_start();//这句话很重要哦!会话开始
$_SESSION["name"]="lovephp";//建立会话
echo "<script>location.href='lovephp.php';</script>";
}
else
{
echo("<script type='text/javascript'> alert('用户名和密码不正确!');location.href='admin.php';</script>");
exit;
}
?>
想要验证的网页中加入
<?php
session_start();
if($_SESSION["name"]!="lovephp"){
echo "<script>location.href='admin.php';</script>";
exit;
}