我正在嘗試將用戶重定向到他們的配置文件,其用戶名在標題中。但是,重定向不顯示用戶名。登錄頁面要求輸入電子郵件和密碼(用戶名省略)。有人能告訴我我做錯了什麼嗎?登錄後重定向到配置文件(PDO)
在class.php:
public function register($uname,$email,$upass,$code)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode)
VALUES(:user_name, :user_mail,
:user_pass, :active_code)");
$stmt->bindparam(":user_name",$uname);
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function login($email,$upass,$uname)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE
userEmail=:email_id AND userName=:user_name");
$stmt->execute(array(":email_id"=>$email,":user_name"=>$uname));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
$_SESSION['userName'] = $userRow['userName'];
return true;
重定向代碼:
public function redirectchannel()
{
header("Location: index.php?id=$userName");
}
登錄頁面:
if(isset($_POST['btn-login']))
{
$email = trim($_POST['txtemail']);
$upass = trim($_POST['txtupass']);
if($user_login->login($email,$upass))
{
$user_login->redirectchannel();
}
}
<input type="email" class="reginput" placeholder="Email address" name="txtemail" required />
<input type="password" class="reginput" placeholder="Password" name="txtupass" required />
<button class="formbutton" type="submit" name="btn-login">Login</button>
和着陸頁:
$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
你在哪裏打電話redirectchannel? – Chris
哪裏的代碼實際顯示任何東西?這裏有很多缺失。 –
在登錄頁面上調用redirectchannel。更新了問題。 – Cordell