Welcome page for first time visitors

Discussion in 'JavaScript' started by VINC, Aug 23, 2011.

  1. #1
    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
     
    VINC, Aug 23, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    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.)
     
    Rukbat, Aug 23, 2011 IP
  3. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #3
    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
     
    VINC, Aug 23, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    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.
     
    Rukbat, Aug 23, 2011 IP
  5. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #5
    but if I rename my real index.php to something else my whole website is messed up and nothing is working, I tried that
     
    VINC, Aug 23, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    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.
     
    Rukbat, Aug 23, 2011 IP
  7. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #7
    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..
     
    VINC, Aug 23, 2011 IP
  8. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #8
    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.)
     
    Rukbat, Aug 23, 2011 IP
  9. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #9
    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
     
    VINC, Aug 23, 2011 IP
  10. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #10
    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?
     
    VINC, Aug 24, 2011 IP
  11. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #11
    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.
     
    Rukbat, Aug 24, 2011 IP
  12. skylark11

    skylark11 Greenhorn

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    yeah,the member abouve is right, this is supposed to be some DNS problem, contact your domain dealer.
     
    skylark11, Aug 24, 2011 IP