我想在 check.php
文件中为我的 panel.php
文件设置 session 。我定义 $_SESSION['admin']= 1
然后在我的 panel.php
文件中评估管理 session 但我不知道为什么我的面板页面重定向到 index.php
(登录表单)。
我带来了以下所有代码:
check.php:
<?php
include_once ("function.php");
$username = $_POST['tfuser'] ;
$password = $_POST['tfpass'] ;
if (isset($username) && isset($password)){
$link = mysql_connect('localhost','root','') or die ('error in connecting to db');
mysql_select_db('login',$link) or die ('error select db');
$sql = "select * from administration
where username='$username' and password='$password'";
$result = mysql_query($sql,$link);
if (mysql_fetch_assoc($result)){
//login to panel
redirect("panel.php");
$_SESSION['admin']= 1 ;
} else {
//back to login page
redirect("index.php?error");
}
} else {
//back to login page
redirect("index.php");
}
?>
panel.php:
<?php
include_once ("function.php");
session_start();
if (!isset($_SESSION['admin'])==1){
session_destroy();
redirect("index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>admin panel</title>
</head>
<body>
welcome to admin panel
</body>
</html>
如何解决此重定向问题?
最佳答案
您对重定向函数的调用是在设置 $_SESSION['admin'] 之前
关于php - 如何评估将用户重定向到管理面板的 PHP session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13101912/