这篇文章主要为大家详细介绍了php 通过Session检查用户是否已经登录的简单示例,具有一定的参考价值,可以用来参考一下。
php通过Session判断检查用户是否已经登录的代码,感兴趣的小伙伴,下面一起跟随四海网的小编罗X来看看吧。
/**
* 通过Session判断检查用户是否已经登录
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
function loggedIn(){
//Session logged is set if the user is logged in
//set it on 1 if the user has successfully logged in
//if it wasn't set create a login form
if(!$_SESSION['loggd']){
echo'<form action="checkLogin.php" method="post">
<p>
Username:<br>
<input type="text" name="username">
</p>
<p>
Password:<br>
<input type="password" name="username">
</p>
<p>
<input type="submit" name="submit" value="Log In">
</p>
</form>';
//if session is equal to 1, display
//Welcome, and whaterver their user name is
}else{
echo 'Welcome, '.$_SESSION['username'];
}
}
/*** 来自四海网(www.q1010.com) ***/
index.php 经测试代码如下:
<?php
//Start the session
session_start();
//This is a simplified HTML Document
?>
<html>
<head>
<title>My Page</title>
</head>
<body>
<?php
//Call the functions file
require_once("functions.php");
//Display either the user's name, or the login form
//This can be placed on many pages without having
//to re-write the form everytime, just use this function
logedIn();
?>
</body>
</html>
/*** 来自四海网(www.q1010.com) ***/
本文来自:http://www.q1010.com/173/309-0.html
注:关于php 通过Session检查用户是否已经登录的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:Session
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。