Welcome page for first time visitors

Discussion in 'Programming' 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
     
    Solved! View solution.
    VINC, Aug 23, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    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:
     
    MyVodaFone, Aug 23, 2011 IP
  3. VINC

    VINC Member

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

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #5
    Working perfectly thank you very much.
     
    VINC, Aug 24, 2011 IP
  6. tony_culy

    tony_culy Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks
    I need infomation it
     
    tony_culy, Aug 24, 2011 IP
  7. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #7
    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
  8. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #8
    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
     
    MyVodaFone, Aug 24, 2011 IP
  9. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #9
    hm still have to double click, I changed the location to a full address but it didnt solve the problem
     
    VINC, Aug 24, 2011 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    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):
     
    Last edited: Aug 24, 2011
    MyVodaFone, Aug 24, 2011 IP
  11. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #11
    VINC, Aug 24, 2011 IP
  12. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #12
    MyVodaFone, Aug 24, 2011 IP
  13. VINC

    VINC Member

    Messages:
    250
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #13
    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
     
    Last edited: Aug 24, 2011
    VINC, Aug 24, 2011 IP