Page 1 of 1
cookies - redirecting to alternating home pages
Posted: Thu Oct 27, 2005 5:23 pm
by dirksmith
Hi
I'd like to set-up a simple cookie system that redirects the user to 1 of 2 home pages - so the home page effectively alternates.
I'm a bit of a php newbie - does anyone know who this is done and what the script would look like?
Thanx
Dirk
Posted: Thu Oct 27, 2005 5:40 pm
by Burrito
so you mean you want the home page to be x the first time they visit and they y the next time, then back to x etc etc?
if so, just create a page with a require_once in it.
check if the cookie is set, if so, check it's value and use a conditional to alternate between the "included" pages, then reset the cookie.
using this scenario would change the home page if they hit a sub page and go back though. You could incorporate sessions as well to prevent that.
Re: cookies - redirecting to alternating home pages
Posted: Thu Oct 27, 2005 6:01 pm
by RobertGonzalez
dirksmith wrote:Hi
I'd like to set-up a simple cookie system that redirects the user to 1 of 2 home pages - so the home page effectively alternates.
I'm a bit of a php newbie - does anyone know who this is done and what the script would look like?
Thanx
Dirk
Something along the lines of ...
Code: Select all
if (isset($_COOKIE['mycookiechecker']))
{
header("Location: http://www.mysite.com/page1.php");
}
else
{
header("Location: http://www.mysite.com/page2.php");
}
CHECK FOR COOKIE EXISTENCE
Posted: Fri Nov 11, 2005 8:47 am
by 4rum
This seems to be troubling me also...
All I need to do is check for the existence of a cookie, and then if necessary grab the value and then do what needs doing. I don't want to use session for this.
Posted: Fri Nov 11, 2005 10:44 am
by RobertGonzalez
Code: Select all
if ( isset($_COOKIE['cookie_name']) )
{
$mycookie = $_COOKIE['cookie_name'];
// Do what you want to do if the cookie exists
}
This is the simplest way. Of course you can always set this comparison to check the value of the cookie var for even greater security.