0

I have this next function:

function checkLoggedIn($status, $redirect=TRUE){ switch($status){ case "yes": if(!isset($_SESSION["loggedIn"])){ if($redirect) { header("Location: login.php"); exit; } else { $authenticated = false; } } else { checkLoggedIn("no"); } break; case "no": if(isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] === true ){ $authenticated = true; } break; } var_dump($authenticated); return $authenticated; } 

The strange this is that when I enable var_dump($authenticated);, I get as output if true:

bool(true) NULL 

and just

bool(false) 

if false

Any ideas why?

1 Answer 1

3

That's because you are calling checkLoggedIn() inside itself.

Sign up to request clarification or add additional context in comments.

3 Comments

oh, I see.. then, any ideas how to avoid the double response?
I'd say put the case "no" code directly in the else statement instead of calling the function again.
bufff, almost impossible because of the way that it was implemented (not by me). I'll find a solution, eventually! Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.