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
cookies - redirecting to alternating home pages
Moderator: General Moderators
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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: cookies - redirecting to alternating home pages
Something along the lines of ...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
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
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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Code: Select all
if ( isset($_COOKIE['cookie_name']) )
{
$mycookie = $_COOKIE['cookie_name'];
// Do what you want to do if the cookie exists
}