Results 1 to 6 of 6

Thread: Redirect - PHP $location?

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Post Redirect - PHP $location?

    I know this may sound weird, but I need it.
    I need to have a page:
    Code:
    http://yourdomain.com/yourfiles/loader.php?location=http://www.yahoo.com
    where it shows "Fetching page" on the screen and then, after 5 seconds, loads Yahoo!.
    Or, by changing the URL, Google.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this:

    Code:
    <?php
    
    if (isset($_GET['location']) && $_GET['location'] != "") {
    
    header('Refresh:5; url='.$_GET["location"]);
    echo 'Fetching Page: '.$_GET["location"];
    
    }
    
    else {
    //if url was not passed, then display form
    ?>
    
    <form action="<?=$_SERVER['PHP_SELF'];?>" method="GET">
    URL: <input type="text" name="location"> <input type="submit" value="Fetch URL">
    </form>
    
    <?php
    }
    
    ?>
    Hope this helps.
    Last edited by thetestingsite; 04-03-2007 at 11:51 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    PHP Code:
    <?php

    if (isset($_GET['location']) && $_GET['location'] != "") {

    header('Refresh:5; url='.$location);
    echo 
    'Fetching Page: '.$_GET["location"];

    }

    else {
    //if url was not passed, then display form
    ?>

    <form action="<?=$_SERVER['PHP_SELF'];?>" method="GET">
    URL: <input type="text" name="location"> <input type="submit" value="Fetch URL">
    </form>

    <?php
    }

    ?>
    could work, but is it possible to display absolutely nothing if no URL? Would it just be:
    PHP Code:
    <?php

    if (isset($_GET['location']) && $_GET['location'] != "") {

    header('Refresh:5; url='.$location);
    echo 
    'Fetching Page: '.$_GET["location"];

    }
    ?>

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by techno_race View Post
    Would it just be:
    PHP Code:
    <?php

    if (isset($_GET['location']) && $_GET['location'] != "") {

    header('Refresh:5; url='.$location);
    echo 
    'Fetching Page: '.$_GET["location"];

    }
    ?>
    You got it. Just remember to call the script like so:

    Code:
    page.php?location=http://www.yahoo.com
    (Remember the http:// or else it will not work properly).
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    My idea of not having else resulted in:
    Quote Originally Posted by fetch.php
    Warning: Cannot modify header information - headers already sent by (output started at /export/home/se/mydomain.com/public_html/fetch.php:3) in /export/home/se/mydomain.com/public_html/fetch.php on line 7
    Fetching Page: http://www.yahoo.com
    (mydomain.com is replacing my website address [se********.com]) Yes, I was using a PHP Web server.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this instead then:

    Code:
    <?php
    
    if (isset($_GET['location']) && $_GET['location'] != "") {
    
    header('Refresh:5; url='.$_GET["location"]);
    echo 'Fetching Page: '.$_GET["location"];
    }
    ?>
    and if that doesn't work, instead of using header redirects use javascript or meta redirects instead.

    Code:
    <?php
    
    if (isset($_GET['location']) && $_GET['location'] != "") {
    echo '<html><head>
    <meta http-equiv="Refresh" content="5;url='.$_GET["location"].'">
    </head>
    <body>
    echo 'Fetching Page: '.$_GET["location"].'</body></html>';
    
    }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •