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'); } } ?>
Â
⇒Understanding and Using Sessions in PHP
⇒⇒PHP Tutorials
2016-10-24, 1015👍, 0💬
Popular Posts:
How To Control Horizontal Alignment in Table Cells? By default, text in all table cells are aligned ...
Where to find tutorials on Using Azure API Management Developer Portal? Here is a list of tutorials ...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...