在我試圖去工作的程序中,我找不到爲什麼我必須登錄兩次才能設置會話。我要前往不同的頁面的方法如下OOP問題設置會話
<?php
if (!isset($_REQUEST['content']))
{
if (isset($_SESSION['gallery_admin']))
include("edit.inc.php");
else
include("adminlogin.php");
}
else
{
$content = $_REQUEST['content'];
$nextpage = $content . ".inc.php";
include($nextpage);
} ?>
,我有一個頁面,用戶與一類在登錄如下它返回session_var一個叫adminlogin.php頁面。 User類做了它應該做的事情,但由於某種原因我必須登錄兩次。我使用相同的代碼,但沒有類,它工作正常。新的PHP和試圖學習面向對象和可以使用幫助。 感謝
public function CheckUser ($username, $hashedpassword)
{
$query = "select count(*) from user where username = ? and password = ?";
$dbConnection = $this->connection;
$stmt = mysqli_prepare($dbConnection,$query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $hashedpassword);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$userCount);
mysqli_fetch($stmt);
if ($userCount > 0)
{
//$_SESSION['gallery_admin'] = $username;
//$user = $this->username;
//$this->session_var = $_SESSION['gallery_admin'];
$this->session_var = $username;
return $this->session_var;
//include ("adminmain.inc.php");
//header("Location: admin.php");
}
else {
return "in the else";
}
}
adminlogin.php
<?php
if (isset($_POST['submit'])) {
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$hashedpassword = md5($password);
$instanceOfUserClass = new User();
$found_user = $instanceOfUserClass->checkUser($username, $hashedpassword);
//$instanceOfUserClass->checkUser($username, $hashedpassword);
//echo $instanceOfUserClass->session_var;
if ($found_user) {
//$user = $instanceOfUserClass->session_var;
$_SESSION['gallery_admin'] = $found_user;
include ("edit.inc.php");
//header("Location: admin.php");
} else {
//echo "No User";
}
}
?>
請用花括號來格式化你的代碼 – 2011-06-02 15:55:01
不知道你的意思花括號什麼? – user747796 2011-06-02 16:05:01