<?php
session_start();
include_once 'db.login.php';
if (isset($_SESSION['users']) != "") {
header("Location: profile.php");
}
if (isset($_POST['btn-login'])) {
$username = mysqli_real_escape_string($con, $_POST['username']);
$upass = mysqli_real_escape_string($con, $_POST['password']);
$res = mysqli_query($con, "SELECT * FROM users WHERE username='$username'");
$row = mysqli_fetch_array($res);
if ($row['password'] == md5($upass)) {
$_SESSION['users'] = $row['id'];
header("Location: profile.php");
} else {
$err = "<p style='color: red'>Wrong Username or Password</p>";
?>
<?php
}
}
?>
我正在尝试的方法,但似乎没有显示任何内容
<?= $_SESSION['username'] ?>">
我基本上是在回应登录会话的用户名
答案 0 :(得分:1)
你在
中填写会话$_SESSION['users']
但是回声
$_SESSION['username']
答案 1 :(得分:-1)
<?php
session_start();
include_once 'db.login.php';
if(isset($_SESSION['users']) && $_SESSION['users'] != "")
{
header("Location: profile.php");
exit();
}
if(isset($_POST['btn-login']))
{
$username = mysqli_real_escape_string($con, $_POST['username']);
$upass = mysqli_real_escape_string($con, $_POST['password']);
$res=mysqli_query($con, "SELECT * FROM users WHERE username='$username'");
$row=mysqli_fetch_array($res);
if($row['password'] == md5($upass))
{
$_SESSION['users'] = $row['id'];
$_SESSION['username'] = $row['username'];
header("Location: profile.php");
}
else
{
$err = "<p style='color: red'>Wrong Username or Password</p>";
?>
<?php
}
}
?>
您没有在任何地方定义$_SESSION['username']
。