[英]Trying to compare two strings
I'm trying to compare two strings. 我正在尝试比较两个字符串。 One of them is a session ( id_usr
), the other is sent via a HTTP GET REQUEST
. 其中一个是会话( id_usr
),另一个是通过HTTP GET REQUEST
发送的。
First I check if the user is logged in and then i want to check if the user who is logged in has the same user id as the one sent via the GET request. 首先,我检查用户是否已登录,然后我要检查登录的用户是否具有与通过GET请求发送的用户ID相同的用户ID。
$id_user = $_GET['id_user'];
$id_user_session = isset($_SESSION['id_usr']);
if(isset($_SESSION) && strcmp($id_user, $id_user_session) == 0) {
echo 'x';
}
Both values look good when i get them, but the compare function strcmp
doesn't work. 当我得到它们时,这两个值看起来都不错,但是比较功能strcmp
不起作用。
What am i missing? 我想念什么?
Change 更改
$id_user_session = isset($_SESSION['id_usr']);
to 至
$id_user_session = $_SESSION['id_usr'];
also make sure that you have started your session with session_start();
还请确保您已使用session_start();
开始了会话session_start();
before trying to access $_SESSION
. 在尝试访问$_SESSION
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.