How to create a redirection page

Discussion in 'PHP' started by Dragoon, Nov 19, 2008.

  1. #1
    Hello,

    I was wondering how to create a code that opens a link, but before it does so it goes to another page that says:

    Redirecting to the destined page in 5 seconds...

    It is sort of like a landing page for all out bound links.

    Please help, Thank you!!
     
    Dragoon, Nov 19, 2008 IP
  2. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #2
    How about this...

    
    
    <?php
        header("Refresh: 3; url=\"http://www.google.com\"");
        echo "You will be redirected to Google in 3 seconds..."
    ?>
    
    
    Code (markup):
     
    Devilfish, Nov 19, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Create:

    redirect.php

    Add the following code to it:

    
    <?php
        header("Refresh: 3; url=\"$_GET[url]\"");
        echo "You will be redirected to $_GET[url] in 3 seconds..."
    ?>
    
    Code (markup):
    Then you just call the page in this format:

    redirect.php?url=http://google.com
    redirect.php?url=http://site.com

    Peace,
     
    Barti1987, Nov 19, 2008 IP
  4. Dragoon

    Dragoon Member

    Messages:
    374
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    30
    #4
    Thanks for the help guys,

    Is there any way to create a link that will link to a website (google.com), but automatically go through my redirection page (mysite.com/redirectpage) and then redirect to google in a set amount of time. (5seconds)

    Thanks

    This may involve .htaccess?
     
    Dragoon, Nov 19, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    This is what azizny's script does. No point doing .htaccess for a simple redirection
     
    ads2help, Nov 19, 2008 IP
  6. Mark Oates

    Mark Oates Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can also do this with HTML:

    <META HTTP-EQUIV="Refresh" CONTENT="2; URL=http://www.address_of_the_website_goes_here.com">
    <p>You are being redirected.  If your browser does not take you there, click <a href="http://www.address_of_the_website_goes_here_too.com">this link</a> to go there manually.</p>
    
    HTML:
    CONTENT="2 is the number of seconds
     
    Mark Oates, Nov 20, 2008 IP
  7. AdultProfiles

    AdultProfiles Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Mark Oates example is very good, and if u want from ur page to redirect again page to google u can add on mysite.com/redirectpage this line: header("Location: google.com); exit(0);
     
    AdultProfiles, Nov 20, 2008 IP
  8. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    you forgot a "

    header("Location: google.com"); exit(0);
     
    atlantaazfinest, Nov 20, 2008 IP
  9. AdultProfiles

    AdultProfiles Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You have right, my mistake :)
     
    AdultProfiles, Nov 20, 2008 IP
  10. eric90

    eric90 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    use javascript:

    onload=setTimeout("location.href='http://www.google.com'",10000)

    the number there is in milliseconds.

    put that code within the opening <body> tag right after the body, so like this

    <body #put code here#> </body>
     
    eric90, Nov 21, 2008 IP
  11. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #11
    If you server supports php, simply use:
    
    header("Location: YOURURL"); die();
    
    PHP:
    Javascript would be crazy to do, as PHP will be the 100% most crossbrowser in this situation.
    Also, if you use javascript, it will show a white page in a second (even if you set the redirect to 0), and then redirect.
    PHP will do an imedially redirect.
     
    elias_sorensen, Nov 21, 2008 IP
  12. eric90

    eric90 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    But the OP wanted it to only redirect after a certain time. header() is immediate.
     
    eric90, Nov 21, 2008 IP
  13. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #13
    Ahh.. Didn't see that.. Sorry.
     
    elias_sorensen, Nov 21, 2008 IP