I want to check if a person has an active session and redirect them to another page when they have one. However, I do not want to use session_start(), as that will place a cookie on the persons PC (I do not want to place cookies on peoples' PC when they're not logged in). Is there a way to check for an existing session, without placing a cookie on their PC?
You can check for the existence of the session ID cookie, which the client would send back if it had been previous set elsewhere in your site:
if (isset($_COOKIE[session_name()])) {
... most likely there's a session available to be loaded ...
}
For added safety, you could then check for the existence of the session file (assuming you're using the default file-based handler) using session_save_path()
and the session_name()
to build up a path to pass into file_exists()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With