我是 php 新手。这是检查用户是否使用会话登录然后允许用户的代码。
验证
<?php
session_start();
$uname = $_POST['uname'];
$pass = $_POST['pass'];
if($uname  == "admin"  &&  $pass == "admin")
{
    $_SESSION['uname'] = $uname;
    $_SESSION['auth'] = 1;
    echo "Welcome Mr ".$uname.". You are now logged in ";
    echo "<br>";
    echo "<a href='TakeMeHome.html'>Click here to access the application </a>";
}
else
{
    echo "Invalid username or password";
}
?>
页
<?php
session_start();
if($_SESSION['auth'] != 1)
{
    echo "You are not logged in! ";
    echo "<a href = \"TakeMeHome.html\">";
    echo "Access Application";
    echo  "</a>";
    exit();
}
?>
<html>
You are now logged in
</html>
但是链接标签正在显示
"; echo "Access Application"; echo ""; exit(); } ?> 
连同html数据。没有进行验证。我知道有很多更好的方法来验证用户是否登录。但我正在学习课程,因此我正在使用课程。你能告诉我哪里出错了吗?
问候。