A
A
Alexander2016-03-03 11:17:38
PHP
Alexander, 2016-03-03 11:17:38

Strange behavior of return $status/true code. In which direction to dig?

There is the following code:

$request= Request::createFromGlobals();
        $token = $request->headers->get("Authorization");
        $status = false;
        $clientId = "xxx";
        $secret = "yyy";
        $secret = base64_decode(strtr($secret, '-_', '+/'));
        try {
            $decodedToken = \Firebase\JWT\JWT::decode($token, $secret, array('HS256'));
            if ($decodedToken->aud === $clientId) {
                $exp = $decodedToken->exp - time();
                if ($exp >= 1) {
                        $status = true;
                }
            }
        } catch (\Exception $e) {
            $status = false;
        }

        return $status;

Angular send request and get error
(Reason: CORS preflight channel failure).

I change return $status; on return true; and everything works, despite the fact that var_dump($status); - bool(true)
Which way to dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2016-03-03
@OxGroup

Understood. My stupidity was. Further on the code was a redirect.
I don’t understand how this is related to using a variable, but if return $status(true) then it worked out the header location
, but only when using the variable there was an error.

A
Andrey, 2016-03-03
@VladimirAndreev

and if you change it to return false, does the error remain?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question