所以我在php
制作了一个简单的登录系统如何在php
上创建一个函数来检查某人是否在线也可以在php
< / p>
登录系统
<?php
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true) {
$errors[] = 'Please Enter a username and password';
} else if (user_exists($username) === false) {
$errors[] ='Sorry but the user you entered dose not exist';
} else if (user_active($username) === false) {
$errors[] ='You have not activated your account please check your email to activate your account';
} else {
if (strlen($password) > 32){
$errors[] ='Passwords to long !';
}
$login = login($username, $password);
if ($login === false) {
$errors[] ='incorrect username or password';
} else {
$_SESSION['user_id'] = $login;
header('Location: index.php');
exit();
}
}
} else {
$errors[] = 'No information received';
}
echo output_errors($errors);
?>
答案 0 :(得分:2)
您可以使用会话:
http://php.net/manual/en/book.session.php
简单使用会话:
// Start the session
if(!session_id())
session_start();
$_SESSION["the_user"] = true;
// To check if the session is alive
if(!empty($_SESSION["the_user"]))
echo "User is online !";
else
echo "User isn't online!";
// Delete the session
unset($_SESSION["the_user"]);
请注意,这只是会话的一个简单用法,即使用户访问该网站,该会话也将处于活动状态。但它会持续几分钟。 (会话的到期时间)