Hi, I need first time visitors to be redirected to www.mydomain.com/welcome.php I have this code: <?php if(isset($_COOKIE['been_here'])){ header('Location: index.real.php'); //change index.real.php to your index page } else { $two_months = 60 * 60 * 24 * 60 + time(); setcookie('been_here', true, $two_months); header('Location: flash.php'); //change flash.php to your desired location for 1st timers } ?> but browser says "too many redirects" and it won't load the website. Any help or tips? Thanks
First time visitors are sent to welcome.php others are sent to index.php or you could change that to just / <?php if(isset($_COOKIE['been_here'])){ header('Location: index.php'); // optional change to header('Location: /'); } else { $two_months = 60 * 60 * 24 * 60 + time(); setcookie('been_here', true, $two_months); header('Location: welcome.php'); } ?> PHP:
and where do I put this to index.php right? But the problem is when I put it into index.php it keeps redirecting itself to index.php and it causes the error
What you can do then is remove the redirection to index.php so basically nothing happens if the visitor has been on your site before. <?php if(isset($_COOKIE['been_here'])){ // do nothing } else { $two_months = 60 * 60 * 24 * 60 + time(); setcookie('been_here', true, $two_months); header('Location: welcome.php'); } ?> PHP: If your site has a configuration file usually 'config.php' or for wordpress wp-config.php that would be the best place to place the code on as its common to all pages loading on your site.
I have one problem now tho. If type in the browser my site: gameswapped.com (without www.) you will see the welcome page and when you click country United States you will get redirected to WWW.gameswapped.com/welcome/welcome.php once again but this time with www. ...you have to click United states one more time to get to the website. Anyway how to stop this?
The links you created for the countries on that page contain www. you could change that or edit the header('Location: welcome.php'); to a full url address header('Location: http://www.gameswapped.com/welcome/welcome.php'); Code (markup): so the www. is carried
hm still have to double click, I changed the location to a full address but it didnt solve the problem
It worked perfectly for me www.gameswapped.com So you need to decide what you want to use... it will make no difference to the end user. You can use .htaccess to insure all visitors landing on www. go to just gameswapped.com or vice versa edit: This will ensure all non www visitors go to www.games.... RewriteEngine on RewriteCond %{HTTP_HOST} ^gameswapped.com$ RewriteRule ^(.*)$ http://www.gameswapped.com/$1 [r=301] Code (markup):
For me it goes to http://www.gameswapped.com/welcome/welcome.php I click United states and it goes again to http://www.gameswapped.com/welcome/welcome.php Then I click United states again and I finally get to www.gameswapped.com Anyway again thanks for your amazing help
Hmm well its working for me, just to clarify I'm visiting www.gameswapped.com after clearing my history and cookies, it takes me to http://www.gameswapped.com/welcome/welcome.php and I can mouse over any of the links and see the correct url for usa www.gameswapped.com I can click that only once and goes directly there
yeah this is how it should be, I tried it in mozzila and chrome and in both it brings me back to welcome page after clicking US and I have to click one more time to get to the website...thats odd.....I placed the code into index.php because when I had it in config.php like you suggested google chrome didnt pick it up...mozzila did. EDIT: Its working now I removed www. from those links of different countries. Thanks again