Reputation: 1303
I am trying to do an introduction page for a website. The trick is, i would only like the user to be redirected here on the first visit. E.g. if he has no session yet. (Although I am not familiar what else to use.) I have been told about .htaccess could do the trick. I use the wordpress engine.
Intro page: http://www.example.com/?page_id=5 (First visitors should be redirected here.) Index page under: http://www.example.com/ (Should not be changed for the engine's mechanisms. In fact this is a custom page too http://www.example.com/?page_id=1, but was selected to be main page in the wordpress options.)
Can you help me? Can you show me specific htaccess code?
Thanks, Sziro
Upvotes: 1
Views: 2066
Reputation: 5891
Cookies may be more reliable than session variables in certain situations:
<?php
$redirect_url = home_url('/welcomepageurlhere');
if ($_COOKIE['returningUser'] == '') {
setcookie('returningUser','1');
wp_redirect($redirect_url);
}
?>
Place that snippet above the <?php get_header(); ?>
line in your page.php template.
Upvotes: 2
Reputation: 2781
Can you edit your php files? php handles sessions more flexibly than .htaccess.
Basically something simple to put at the top of your header.php (before anything else gets executed).
<?php
$redirect_url = home_url('/?page_id=5');
if ( !isset($_SESSION['blablabla']) ) {
$_SESSION['blablabla'] = "blablabla";
wp_redirect($redirect_url);
}
?>
This way whenever any page is accessed (since wordpress includes the header in requested pages), php checks if the session (specifically $_SESSION['blablabla']) has been set, if not then redirect to the home page.
Upvotes: 3