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
1) Are you getting that message with no cookie, or once you get the cookie? 2) Do you have any redirect on your real or first-time pages? (If either of them redirects back to this page, it won't work.)
Yeah once I get the cookie. I think the problem is I am putting the code into index.php so once I get cookie it redirects to itself. But how to solve it? Where do I put the code? Thanks
You can't have index.php redirect to this page, then have this page redirect to index.php. You need this code in index.php, then redirect to either your real index.php (which you name something else, it doesn't matter what) or to a "welcome, new visitor" page, depending on whether index.php found the cookie or not. BTW, I'd rewrite the cookie if it's found, so they always have 2 months to not be "new". Otherwise 2 months after they first come to the site, they're new again.
but if I rename my real index.php to something else my whole website is messed up and nothing is working, I tried that
No other file should link to index.php, they should all link to the real (renamed) index.php. Index,php is just a file that determines whether the user has a cookie. You could rewrite index.php so that it serves both functions, checking the cookie and being the real index.php file, but it's going to be a lot easier for you to just rename the real index.php and change any references to it.
there is exactly 435 references to index.php in my script. Whatever you click on my site the url looks like this: www.mysite.com/index.php?option=blabla........ index.php is loading with anything I click and when I change that file nothing is working..
Use a text editor that can do a global change and you can change 435 occurrences as easily as you can change 1. I believe UltraEdit can do that (although I don't use it, but some of the people I work with do). And I think there's a free 30 day trial. The only other way is to completely redesign index.php so that it can rerun itself without causing a redirect loop, and I can't do that for you, you'll have to learn enough programming to figure out what you need. (BTW, channeling everything through your default file is a very bad idea - for the reason you've already seen, among other things.)
I have a zero coding experience so I am afraid I am gonna mess up the whole script. Anyway your help is much appreciated, thank you for your time
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?
That sounds like a DNS problem - talk to whoever you bought the domain name from. With or without the www, the address should resolve to the same IP. It doesn't.
yeah,the member abouve is right, this is supposed to be some DNS problem, contact your domain dealer.