dongzhitao4839 2015-11-15 18:49
浏览 53
已采纳

PHP $ session_start()无法正常工作[关闭]

I want to create a PHP account system to access special parts of my website. The login info (page 1) is fed to the check page (page 2) which checks that the info is right, which then redirects to the member page (page 3)

Page 1:

    <form action="inner.php" method="post" class="centered">
    <input type="text" name="usr" placeholder="Username" required><br>
    <input type="password" name="psw" placeholder="Password"required><br>
    <input type="submit" name="submit" value="Log In">
    </form>

Page 2:

    <?php
    session_start();

    if ( $POST_["usr"] = "felix" || $POST_["psw"] = "password")
    {

    $_SESSION["usr"] = $POST_["usr"];

    header('Location: member.php');
    }
    else
    {
    header('Location: index.php');
    }
    ?>

Page 3

    <?php
    session_start();
    $usr = $_SESSION["usr"];

    if( $usr = felix)
    {
    $name = 'Felix';
    $admin = 'true';
    }
    else
    {
    header('Location: index.php');
    }

    $felix = 'felix@example.com';
    ?>
  • 写回答

1条回答 默认 最新

  • dongwenxiu5200 2015-11-15 19:00
    关注

    Page 2

    // $_POST instead of $POST_, wrong variable name
    // == instead of =, compare, don't assign
    // && instead of ||, usually it is username AND password, not one of both
    // additional isset() against "undefined index"-notices
    if (isset($_POST['usr']) && isset($_POST['psw']) &&
        $_POST['usr'] == "felix" && $_POST['psw'] == "password")
    {
        // Again $_POST instead of $POST_
        $_SESSION["usr"] = $_POST["usr"];
        header('Location: member.php');
    } else {
        header('Location: index.php');
    }
    

    Page 3

    <?php
    session_start();
    $usr = (isset($_SESSION["usr"]) ? $_SESSION["usr"] : "");
    if (isset($_SESSION["usr"])) {
        $usr = $_SESSION["usr"];
    }
    // Again == instead of =
    if ($usr == "felix") {
        // Rest of the script
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行