突然我的網站管理面板不再工作,我已經厭倦許多方式來編輯它,所有都是faild。由於會話管理面板不工作
請告訴我哪裏有錯誤應該是
數據庫
CREATE TABLE `egadmin` (
`AdminID` int(10) NOT NULL auto_increment,
`username` varchar(50) NOT NULL default '',
`password` varchar(50) NOT NULL default '',
PRIMARY KEY (`AdminID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `egadmin` VALUES (1, 'admin', 'pass');
conn.php [連接文件]
<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "mypass";
$db_name = "dbname";
$connection = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());
$db = mysql_select_db($db_name, $connection);
?>
的index.php [登錄表單]
<form action="validate.php" method="post">
ID <input type="text" name="userid" id="userid" />
Password <input type="password" name="password" id="password" />
<input type="submit" name="submit" value="Submit" />
</form>
validate.php [登錄形式發送給validate.php]
<?php
require_once("conn.php");
$user = $_POST["userid"];
$pass = sha1($_POST["password"]);
$query = "SELECT * FROM egadmin WHERE username = '$user' AND password = '$pass'";
$result = mysql_query($query);
if (mysql_fetch_row($result)) {
session_start();
header("Cache-control: private");
$_SESSION["access"] = "granted";
header("Location: secure.php");
} else
header("Location: index.php");
?>
secure.php [應該是受保護的文件]
<?php
session_start();
header("Cache-control: private");
if ($_SESSION["access"] == "granted")
echo "blah blah blah";
else
header("Location: index.php");
?>
的問題
每當我輸入正確的登錄信息(用戶名,密碼)時,它會重新發送給我登錄窗體(index.php),因此看起來它根本無法創建$ _SESSION。
任何幫助,請如何解決它,或者爲什麼這個錯誤
注:PHP 5.2.17版本| register_globals =開(如果關閉也不起作用)
嘗試將session_start()放入您的validate.php – OptimusCrime 2012-01-27 15:09:05