Hi
I put the following code into my functions.php file. Here's what I want:
1. I want the cookie to be set only when the visitor goes to Post 1.
2. When someone visits Post 2, if they have the cookie, they get redirected to Post 3. If they don't have the cookie, nothing happens.
Now it seems to be working, but the problem is sometimes, when the cookie isn't set, I get redirected to Page 3 from the home page :s. I have no idea why.
I should mention I know nothing about coding. The code below is stuff I got online, mixed and matched it, and did some trial and error with my blog.
function set_newuser_cookie() {
$currentURL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//THE ABOVE GETS THE CURRENT URL
if (!isset($_COOKIE['subscriber']) && $currentURL == 'http://mysite.com/post1') {
setcookie('subscriber', no, 0, COOKIEPATH, COOKIE_DOMAIN, false);
//THE ABOVE SETS A COOKIE IF IT FINDS THE CURRENT URL IS /POST1
}
}
add_action( 'init', 'set_newuser_cookie');
//I DON'T KNOW WHAT THE ABOVE IS, BUT I HEAR IT'S IMPORTANT
$currentURL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//THE ABOVE GETS THE URL AGAIN
if ( isset( $_COOKIE["subscriber"] ) && $currentURL == 'http://mysite.com/post2' ) :
header( "Location: http://mysite.com/post3" );
endif;
//THE ABOVE REDIRECTS THE VISITOR TO POST3 ON 2 CONDITIONS: 1. THAT THE COOKIE IS SET, 2. THAT THE CURRENT URL IS /POST2
Please help!