Aleix Gallet Segarra
Aleix Gallet Segarra

Reputation: 25

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.

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.

$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.

What am i missing?

Upvotes: 0

Views: 48

Answers (1)

Adam
Adam

Reputation: 29079

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();before trying to access $_SESSION.

Upvotes: 2

Related Questions