在我试图去工作的程序中,我找不到为什么我必须登录两次才能设置会话。我要前往不同的页面的方法如下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