作者:机加工N_918 | 来源:互联网 | 2017-05-13 02:18
界面:
<html><head><title>Logintitle>head><body><formname="fangbei"method="post"action="check_session_login.php"><pstyle="width:353"><dl><dt>dt><dd><palign="left">
Username:
<inputtype="text"name="username" />p>dd><dd><palign="left">
Password :
<inputtype="password"name="pwd" />p>dd><dd><palign="center"><inputtype="submit"name="Submit"value="Submit" /><inputtype="reset"name="Reset"value="Reset" />p>dd>dl>p>form>body>html>
数据库准备:
username | pwd | userflag |
perry | 123 | 1 |
登录验证:
header("Content-Type: text/html; charset=utf-8");
$servername="localhost";
$username = "root";
$password = "";
$dbname = "paul";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->query("SET NAMES utf8");
//获取输入的信息$username = $_POST['username'];
$pwd = $_POST['pwd'];
//获取session的值$sql = "select username,userflag from test_login where username = '$username' and pwd = '$pwd'";
$result = $conn->query($sql);
//判断用户以及密码if ($result->num_rows > 0) {
session_start();
//判断权限$row = $result->fetch_assoc();
if($row['userflag'] == 1or$row['userflag'] == 0){
$_SESSION['username'] = $row['username'];
$_SESSION['userflag'] = $row['userflag'];
echo"欢迎访问";
}
else{
echo"迷之用户";
}
}
else{
echo"用户名或密码不正确";
}
欢迎界面:
header("Content-Type: text/html; charset=utf-8");
session_start();
if(isset($_SESSION['username']))
{
if($_SESSION['userflag'] == 1)
echo"欢迎管理员".$_SESSION['username']."登录";
if($_SESSION['userflag'] == 0)
echo"欢迎用户".$_SESSION['username']."登录";
}
else
{
echo"登录已过期";
}
unset($_SESSION['username']);
unset($_SESSION['pwd']);
unset($_SESSION['userflag']);
echo"
会话结束";
').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i <= lines; i++) {
$numbering.append($('
').text(i));
};
$numbering.fadeIn(1700);
});
});
以上就介绍了PHP登录session验证实例,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。