0

session_status() keeps returning 1 (PHP_SESSION_NONE) every time I visit localhost page. I know storing variables, session_start() and session_destroy() work because of the files in c:\xamp\tmp (defined in php.ini)

But why doesnt it register as session in code?

if (session_status() === PHP_SESSION_NONE) {
    session_start();
    echo session_status();
} else{
    echo "active";
}

Any help would be appreciated, thank you

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
djulb
  • 375
  • 1
  • 3
  • 19
  • 2
    [Did you read the manual on `session_status()`?](https://www.php.net/manual/en/function.session-status.php). – Funk Forty Niner Feb 05 '20 at 20:04
  • 1
    Unless you have `session_start` somewhere before the `if` then how would it be active? – AbraCadaver Feb 05 '20 at 20:11
  • Ohh - I did read it before, but I guess I didnt understand it :/ I was banging my head for an hour with that. Having a slow day Thank you. For some reason I thought php does it automatically when it receives phpid – djulb Feb 05 '20 at 20:15
  • You're welcome. Just glad that you went over it and figured it out :) Cheers! @bevelod – Funk Forty Niner Feb 05 '20 at 20:18

1 Answers1

3

we mostly use isset for condition on session variable

if(isset($_SESSION['var'])){
    echo "Welcome". $_SESSION['var'];
}

maybe its helpfull for you :)

Waleed Muaz
  • 737
  • 6
  • 17