PHP Session Help (Single Page)
Posted: Tue May 04, 2010 9:56 am
Hello all,
The client wants to display a flash intro page (preferrably once a week). I wrote a solution using cookies, but I realized if they weren't allowing cookies they would never get past the front page. So I figured I could set a $_SESSION token to get them in anyways, they would just see the intro page everytime (not once a week).
However, I can't seem to get it to work. Can anyone take a look?
It works in a cookie-enabled browser however if I disable cookies, it just hangs on the intro page.
I have the 2 print_r's in check and its giving me this:
Does session_start clear the session, so it's erasing the fact that I just set it? How can I work around this?
The client wants to display a flash intro page (preferrably once a week). I wrote a solution using cookies, but I realized if they weren't allowing cookies they would never get past the front page. So I figured I could set a $_SESSION token to get them in anyways, they would just see the intro page everytime (not once a week).
However, I can't seem to get it to work. Can anyone take a look?
Code: Select all
<?php
session_start(); //start PHP session
print_r($_SESSION);
//if the intro hasn't been viewed
if(!isset($_COOKIE['viewed_intro']) || !isset($_SESSION['viewed_intro'])){
//set the viewed_intro cookie so they don't see the flash intro again
//5 second debug
setcookie ('viewed_intro', 'Yep, I viewed it', time() + 5);
//set the session
$_SESSION['viewed_intro'] = 'Yep, I viewed it';
print_r($_SESSION);
?>
FLASH INTRO GOES HERE
<?php
}else{
?>
HTML WEBSITE GOES HERE
<?php
}
?>I have the 2 print_r's in check and its giving me this:
I know the issue is it's failing the if check. But why?Array ( ) Array ( [viewed_intro] => Yep, I viewed it )
Does session_start clear the session, so it's erasing the fact that I just set it? How can I work around this?