Showing something for 120 seconds
I need to show something on all pages on a site for 120 seconds after the user hits the site
I am setting a session up with
session_start();
if(!isset($_SESSION['phonecookie'])){
$_SESSION['phonecookie'] = array("expire"=>time()+60*2);
}
then to display the content I am using this on all of the pages.
session_start(); //if not already called with the above statement
if(isset($_SESSI开发者_开发知识库ON['phonecookie']['expire'])){
if($_SESSION['phonecookie']['expire'] >= time()){
echo "the content";
}
}
for some reason on refresh of a page it keeps changing the value of the phonecookie session value even though I am only generating the phonecookie session value if it doest exist.
isset()
checks whether a variable exists. $_SESSION
behaves like an array. I would advise to use one of these:
if (!empty($_SESSION['phonecookie']['expire']) {}
or
if (array_key_exists('expire', $_SESSION['phonecookie'])) {}
精彩评论