douyanning3724 2014-12-24 19:04
浏览 9

首次登录时不会创建php会话

I have a problem setting up a session. Every time i commit log in to the site the session should be created, but it isn't so and i am redirected to notvalid.php. The session is created only the second time i try to log in

session_start(); is the first line at every page at my website.

This are the connection functions:

public static function Login($name, $pass)
    {
    if (!empty($name) && !empty($pass))
        {
        global $dbh;
        $result = $dbh->query("SELECT * FROM users WHERE username = '" . $name . "' AND password = '" . $pass . "'");
        $row = $result->fetch(PDO::FETCH_ASSOC);
        if ($row > 0)
            {
            $userid = $row['userid'];
            $_SESSION['userid'] = $userid;
            $_SESSION['login'] = 'true';
            echo '<META HTTP-EQUIV="Refresh" Content="0; URL=userindex.php">';
            }
          else
            {
            echo "incorrect username or password.";
            $_SESSION['login'] = 'false';
            }
        }
    }

this function check if the session exist:

public static function checklogin()
    {
    if ($_SESSION['login'] == 'true')
        {
        return $_SESSION['userid'];
        }
      else
        {
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=notvalid.php">';
        }
    }

I have tried to enter the site with or without www, i have tried to do as they suggest here

PHP login session wont work on first page load in a NEW window with no cache

But nothing helped.

Any help would be graet.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大