PHP Page Redirect Based Upon Cookies
Moderator: General Moderators
PHP Page Redirect Based Upon Cookies
I have a client that is running a short term promotion on their site. They want to have a splash page with the promotional information on it, but they only want the user to see the splash page once. If the user has already seen it, they want the user to go right to the regular home page of the site.
I was thinking that this can be done in PHP using a redirect based upon setting a cookie, but does anyone know how you could code this, or if there is better/more efficient way of doing this?
I was thinking that this can be done in PHP using a redirect based upon setting a cookie, but does anyone know how you could code this, or if there is better/more efficient way of doing this?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
isset(), $_COOKIE, setcookie() is really all you need to get started.
I need to do a series of if statements though that checks to see if the cookie is present. If it is not present, it sets the cookies and renders a chunk of HTML code.feyd wrote:isset(), $_COOKIE, setcookie() is really all you need to get started.
If the cookies is already present, the user sees the rest of the page and not the promotional code.
Just use something akin to the following:
Code: Select all
if(isset($_COOKIE['value'])) {
// present the page without setting the cookie
} else {
// set the cookie
}feyd | Please use
In the splash.php file I have:
The splash.php file just keeps refreshing in the browser every 9 seconds and the user never goes to index.php from there.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Still can't get this to work properly.
At top of my index.php file, I have the following:Code: Select all
<?php
if (!isset($_COOKIE['RafflePromo']))
{
setcookie("RafflePromo","1",time()+3600*24*365*30);
header('Location: splash.php');
}
?>Code: Select all
<html>
<head>
<meta http-equiv="refresh" content="9;url=index.php" />
<title>A Message from the New York State Lottery...</title>
<link rel="stylesheet" type="text/css" media="screen" href="interstitial.css" />
</head>
<body>
<div align="center"><a href="index.php"><img src="testheader.jpg" width="749" height="54" border="0" alt="Raffles to Riches coming soon!"></a></div>
<p align="center"><img src="rafflepromo.jpg" width="500" height="500" border="2" alt="Raffles to Riches coming soon!"></p>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
try
Code: Select all
setcookie("RafflePromo","1",strtotime('+10 years'));didn't work.Kieran Huggins wrote:tryCode: Select all
setcookie("RafflePromo","1",strtotime('+10 years'));
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Make sure error_reporting(E_ALL) is set and possibly ini_set('display_errors', 1).