Tools, FAQ, Tutorials:
Determining If a Session Is New in PHP
How To Determine If a Session Is New in PHP?
✍: FYIcenter.com
There is not direct way to tell if a session is new or old. But you can design your site to have a required session value in all sessions. Then you can check the existence of this value in a session to determine if it is a new session by isset($_SESSION['name']).
Let's say you decided to have a required session value called "Status" with two possible values: "Guest" and "Registered". The landing script of your site should look like:
<?php
session_start();
if (!isset($_SESSION['Status'])) {
$_SESSION["Status"] = "Guest";
print("<html><pre>");
print("Welcome to FYICenter.com!\n");
print(" <a href=login.php>Login</a>\n");
print(" <a href=guest_home.php>Stay as a guest</a>\n");
print("</pre></html>\n");
} else {
if ($_SESSION["Status"] == "Guest") {
header( 'Location: http://localhost/guest_home.php');
} else if ($_SESSION["Status"] == "Registered") {
header( 'Location: http://localhost/home.php');
}
}
?>
⇒ Closing a Session Properly in PHP
⇐ Removing Values Saved in the Session in PHP
2016-10-24, ∼2736🔥, 0💬
Popular Posts:
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...
How to use the RSS Online Validator at w3.org? You can follow this tutorial to learn how to use the ...
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...