gpt4 book ai didi

PHP 查询数据库内的 Session_ID

转载 作者:行者123 更新时间:2023-11-29 06:10:47 26 4
gpt4 key购买 nike

我一直在尝试在我的网站上查找 session ID,以便可以使用它来查询我的 MySQL 数据库,但我不断收到错误“ undefined variable :_SESSION in...”

这是我的代码:

if (mysql_num_rows(mysql_query("SELECT * FROM users WHERE _id = " . $_SESSION['_id_of_user'])))

这是我定义 session ID 的地方:

$qry = "Select name, email, username, _id from $this->tablename where username='$username' and password='$pwdmd5' and confirmcode='y'";

$result = mysql_query($qry,$this->connection);

if(!$result || mysql_num_rows($result) <= 0)
{
$this->HandleError("Error logging in. The username or password does not match");
return false;
}

$row = mysql_fetch_assoc($result);

$_SESSION['name_of_user'] = $row['name'];
$_SESSION['email_of_user'] = $row['email'];
$_SESSION['username_of_user'] = $row['username'];
$_SESSION['_id_of_user'] = $row['_id'];

最佳答案

您必须在 sql 查询之前启动 session : http://us.php.net/manual/en/function.session-start.php

session_start();

然后你应该通过以下方式获取当前 session ID: http://us.php.net/manual/en/function.session-id.php

$current_session_id = session_id();

关于PHP 查询数据库内的 Session_ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com