我正在创建一个登录表单并使用会话注销,但是当我尝试登录浏览器时显示错误(我认为错误出现在记录的功能中)任何人都可以帮助我,因为它让我发疯...... **页面是'重定向不正确 Firefox 的服务器正在以一种永远不会检测到完成的方式重定向对该地址的请求。
此问题有时可能是由禁用或拒绝接受 cookie 引起的。**
登录.php
<?php
ob_start();
require_once('functions.php');
if(loggedin()){
header("Location: userarea.php");
exit();
}
if(isset($_POST['login'])){
//get data
$username = $_POST['username'];
$password = $_POST['password'];
$rememberme = $_POST['rememberme'];
if($username && $password){
$login = mysql_query("SELECT * FROM rememberme WHERE username = '$username'");
while($row = mysql_fetch_assoc($login)){
$db_password = $row['password'];
if($password == $db_password)
$loginok = TRUE;
else
$loginok = FALSE;
if($loginok == TRUE){
if($rememberme == "on"){
setcookie("username", $username, time()+7200);
}else if($rememberme == "")
$_SESSION['username'] = $username;
header("Location: userarea.php");
exit();
}else{
die("incorrect username/password combination");
}
}
}else
die("please enter a username and password");
exit();
}
?>
<form action="login.php" method="post">
<p>Username<br />
<input type="text" name="username" />
</p>
<p> Password<br />
<input type="password" name="password" />
</p>
<p>
<input type="checkbox" name="rememberme">
Remember me<br />
<input type="submit" name="login" value="Log in" />
</p>
</form>
<?php ob_flush(); ?>
函数.php
<?php
//session
session_start();
// connect to database
mysql_connect("localhost", "root", "") or die("could not connect to database");
mysql_select_db("rememberme") or die("could not select database");
// login check function
function loggedin()
{
$loggedin = false;
if(isset($_SESSION['username'])||isset($_COOKIE['username']))
{
$loggedin = TRUE;
}
return $loggedin;
}
?>
用户区.php
<?php
//session
session_start();
// connect to database
mysql_connect("localhost", "root", "") or die("could not connect to database");
mysql_select_db("rememberme") or die("could not select database");
// login check function
function loggedin()
{
if(isset($_SESSION['username'])||isset($_COOKIE['username'])){
$loggedin = TRUE;
return $loggedin;
}
}
?>