Validating a login using PHP

34 Views Asked by At

This is definitely a duplicate of my previous question. Once I understood what was going on, I tried editing my original question but it wouldn't save. I tried logging out and logging back in, but I couldn't update it, so I made a new question with the more detailed info.

The user in this scenario has to login to my application using the following link for our company's SSO:

https://example.com/signin.jsp?%20realm=auth&gotoURL=http://example.com/myURL/

After signing in here, they are redirected back to my website.

I'm trying to make something in PHP to determine whether or not the user has logged in, and my initial thought was to use cURL/PHP.

I can check whether or not they are logged in to our SSO using the same example.com website, here:

http://example.com/isTokenValid?

If this is true, they continue, if not, they get redirected back to the login page.

When I type http://example.com/isTokenValid? into the browser, I see either:

boolean=true

or

boolean=false

I don't know how to get PHP to recognize these outputs though. I tried the following:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/isTokenValid?');
$answer = curl_exec($ch);

I'm confused by the response though.

Whether or not I'm logged in, If I execute JUST this code, I see

boolean=false

(although I don't know where this is coming from since I have no echo in this code..)

However, if I execute this code along with var_dump($answer); I see

boolean=false
bool(true)

What am I doing wrong with my code? Is it my PHP? my cURL? Am I going about this all wrong? All i want to do is read this boolean value to determine whether or not the login took place successfully. Do I need to use a session somewhere?

0

There are 0 best solutions below