我的目标是使用会话变量更改头文件中的内容。 场景是:
任何想法?登录正在运行但内容未更改。提前谢谢!
[更新]:问题解决了!我忘了声明变量$ row($ row = mysqli_fetch_assoc($ result);)
index.php文件:
<?php
include_once 'header.php';
?>
.
.
.
header.php文件:
<?php
session_start();
?>
.
.
.
<?php
if (isset($_SESSION['u_id']))
{
echo "User is: " . $_SESSION['u_first'] . "now" ;
}
else
{
echo "Login first";
}
?>
login.php文件:
<?php
session_start();
if (isset($_POST['submit']))
{
include 'dbh.inc.php';
$uid = mysqli_real_escape_string($conn,$_POST['uid']);
$pwd = mysqli_real_escape_string($conn,$_POST['pwd']);
$sql = "SELECT * FROM users WHERE user_uid = '$uid' AND user_pwd = '$pwd' ";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck < 1)
{
header("Location: ../index.php?login=error");
exit();
}
else
{
//LOGIN
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../index.php?login=success");
exit();
}
}
else
{
header("Location: ../index.php?login=error");
exit();
}