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'); } } ?>
2016-10-24, 404👍, 0💬
Popular Posts:
How Values in Arrays Are Indexed in PHP? Values in an array are all indexed their corresponding keys...
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to add a new operation to an API on the Publisher Dashboard of an Azure API Management Service? ...
How to see more EPUB 2.0 metadata list with Calibre? You can follow this tutorial to view EPUB 2.0 m...