Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: First time visitor be redricted to a welcome page

  1. #1
    Join Date
    Dec 2008
    Posts
    29
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default First time visitor be redricted to a welcome page

    Hi everyone,

    I know next to zero about JS script. Sorry for I may be asking a stupid question. I am looking for a JS script that will redirect the first time visitor to a welcome page which has a flash introduction script, and if they have been to my site before, then they will be directed to the index page instead of welcome page. My site is a PHP site. Is it possible?

    Thank you very much.
    Last edited by jackson; 12-21-2008 at 07:14 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here's a PHP way of doing it. I've set a cookie and the cookie will last for two months or until the user clears their cookies.
    PHP 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
    }
    ?>
    Jeremy | jfein.net

  3. #3
    Join Date
    Dec 2008
    Posts
    29
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Here's a PHP way of doing it. I've set a cookie and the cookie will last for two months or until the user clears their cookies.
    PHP 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
    }
    ?>
    Sorry Nile,

    May I ask where do I put this script? Do I make a new PTL and PHP pages, or do I put it into header? Thanks for your help.

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    If your server supports PHP (which many do), put that code into your .php page (you'll want to save it as .php). It's just like having regular code. Take an HTML page, for example. Just put the code Nile provided into the <head> or wherever you want it and the pre-processor will do the rest.

    -magicyte

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What you want to do is put that in your index.php, if you want it to redirect to another page(if someone has already been to the site) then you would beed to change that in the code. If you just want it to stay on the same page if someone has already been to your site use this:
    PHP Code:
    <?php
    if(!isset($_COOKIE['been_here'])){
        
    $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
    }
    ?>
    And put it above everything else.
    This code maybe a little bit easier for you to use:
    PHP Code:
    <?php
    $location 
    = array();//make an array
    $location[0] = "#"//This is the location you want it to go if someone has been to your site, if you want it to stay on the same page use #.
    $location[1] = "flashIntro.html"//This is the location you want someone to go if they have not been to your site, to stay on the same page use #.

    if(isset($_COOKIE['been_here'])){ //see if the cookie exists
        
    if($location[0]!='#'){ //if it does, check and see if the location[0] doesn't equals #
            
    header("Location: $location[0]"); //if it doesn't redirect to location [0]
        
    } else { //if it does
            //go nowhere, stay put
        
    }
    } else { 
    //If there isn't a cookie called been_here with a value of "true" or 1, or a true statement
        
    $two_months 60 60 24 60 time(); //2 months
        
    setcookie('been_here'true$two_months); //set  a cookie called been_here with a true statement
        
    if($location[1]!='#'){ //check to see if the location[1] doesn't equal #
            
    header("Location: $location[1]"); //if it doesn't redirect to location[1]
        
    } else { //if it does
            //go nowhere, stay put
        
    }
    }
    ?>
    Put it above everything else.
    If you want to redirect to a different page when someone has been to your site before change the value of $location[0] to the location you want it at. If you don't want it to redirect change it to '#' which tells the script to stay put.

    If you want to redirect to a different page when someone has not been to your site, change the value of $location[1] to the location you want it at. If you don't want it to redirect change the value to: '#'.
    Last edited by Nile; 12-19-2008 at 08:51 PM.
    Jeremy | jfein.net

  6. The Following User Says Thank You to Nile For This Useful Post:

    jackson (12-20-2008)

  7. #6
    Join Date
    Dec 2008
    Posts
    29
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    What you want to do is put that in your index.php, if you want it to redirect to another page(if someone has already been to the site) then you would beed to change that in the code. If you just want it to stay on the same page if someone has already been to your site use this:
    PHP Code:
    <?php
    if(!isset($_COOKIE['been_here'])){
        
    $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
    }
    ?>
    And put it above everything else.
    Hi Nile,

    I just put these codes in my index.php, and it works perfectly. Will the cookie expire in two months? How can I change it to last until the users clear the cookies which may be longer than 2 months? Thank you very much for all of your help.
    Last edited by jackson; 12-20-2008 at 10:43 PM. Reason: One more question

  8. #7
    Join Date
    Dec 2008
    Posts
    29
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by magicyte View Post
    If your server supports PHP (which many do), put that code into your .php page (you'll want to save it as .php). It's just like having regular code. Take an HTML page, for example. Just put the code Nile provided into the <head> or wherever you want it and the pre-processor will do the rest.

    -magicyte
    My page is working perfectly now. Thank you very much for your help.
    Last edited by jackson; 12-20-2008 at 10:42 PM.

  9. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, well I don't know which code your using, but I highly suggest this one:
    Quote Originally Posted by Nile View Post
    This code maybe a little bit easier for you to use:
    PHP Code:
    <?php
    $location 
    = array();//make an array
    $location[0] = "#"//This is the location you want it to go if someone has been to your site, if you want it to stay on the same page use #.
    $location[1] = "flashIntro.html"//This is the location you want someone to go if they have not been to your site, to stay on the same page use #.

    if(isset($_COOKIE['been_here'])){ //see if the cookie exists
        
    if($location[0]!='#'){ //if it does, check and see if the location[0] doesn't equals #
            
    header("Location: $location[0]"); //if it doesn't redirect to location [0]
        
    } else { //if it does
            //go nowhere, stay put
        
    }
    } else { 
    //If there isn't a cookie called been_here with a value of "true" or 1, or a true statement
        
    $two_months 60 60 24 60 time(); //2 months
        
    setcookie('been_here'true$two_months); //set  a cookie called been_here with a true statement
        
    if($location[1]!='#'){ //check to see if the location[1] doesn't equal #
            
    header("Location: $location[1]"); //if it doesn't redirect to location[1]
        
    } else { //if it does
            //go nowhere, stay put
        
    }
    }
    ?>
    To change it from two months find the following line:
    Code:
        $two_months = 60 * 60 * 24 * 60 + time(); //2 months
    Jeremy | jfein.net

  10. #9
    Join Date
    Dec 2008
    Posts
    29
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Ok, well I don't know which code your using, but I highly suggest this one:


    To change it from two months find the following line:
    Code:
        $two_months = 60 * 60 * 24 * 60 + time(); //2 months
    Thank you Nile,

    I have used the codes that you suggested above. It works perfectly. I found the code
    Code:
        $two_months = 60 * 60 * 24 * 60 + time(); //2 months
    , if I want to change the 2 months to forever, what should I change? It sounds a stupid question, but I really don't know what to change. Sorry...

    Jack

  11. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    There is no way to make it last forever, but you can make it last an amount of days:
    Code:
    $two_months = strtotime('+365 days'); //2 months
    Jeremy | jfein.net

  12. The Following User Says Thank You to Nile For This Useful Post:

    jackson (12-21-2008)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •