Reputation: 2203
I have a landing page that I would like viewers to see when first arriving at //domain.com. Then, if they have been to the site before the browser would automatically skip the landing page and take them directly to //domain.com/main.html
What is the best approach to do this?
Upvotes: 1
Views: 2377
Reputation: 82028
If I were you, I would actually re-direct if they haven't seen the page the first time. It creates a more intuitive URL.
Either way, strictly speaking, you want to use setcookie
the first time that the person visits the site, and then test to see if the value exists in $_COOKIE
upon return. Realistically, you probably want:
Why do you want to set the value after the use clicks a link? Well, that way you can force them to actually look at the page before continuing, and I think that is more what you want.
Your redirect might look like:
if( !isset( $_COOKIE[ 'seen_landing_page' ] ) )
{
header( 'Location: <other page>' );
die();
}
// do whatever else here.
You can then have a simple pass-through page:
setcookie('seen_landing_page',TRUE);
header( 'Location: <your main page>' );
Upvotes: 2
Reputation: 53871
Something like this?
// index.php
if ( !isset($_COOKIE["been_here"]))
setcookie("been_here",true);
else
header("Location: main.html");
Upvotes: 2