Results 1 to 7 of 7

Thread: redirecting

  1. #1
    Join Date
    Sep 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default redirecting

    location.php

    Code:
    <?php
    include("mysql_connect.php");
    $id =$_GET['id'];
    $sql=mysql_query("SELECT * FROM topics WHERE id='".$id."'");
    if($row=mysql_fetch_array($sql))
    header("Location:{$row['webpage']}");
    mysql_close($con);
    ?>

    with the above scrpt it is redirecting me to http://localhost/pro1/facebook.com istead of facebook.com
    the link with which this script get intiated is like this localhost/pro/location.php?id=21
    there is a corresponding webpage in the table coresponding to that particular unique id...how to make this script go to http://domain.com
    instead of localhost/pro/domain.com

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    PHP Code:
    <?php
    include("mysql_connect.php");
    $id =$_GET['id'];
    $sql=mysql_query("SELECT * FROM topics WHERE id='".$id."'");
    if(
    $row=mysql_fetch_array($sql))
    header("Location: http://{$row['webpage']}");
    mysql_close($con);
    ?>
    Either change your code as above, or just add "http://" to the beginning of the webpage values.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    PHP novice here. But I'm under the impression that you cannot redirect unless it is the very first directive.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    As long as there's no output before the header, then it's fine ^^

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Ah, but isn't an include output?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    John,
    Only if the file being included outputs something, but if it just has some variables or functions, then it should be fine.

    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

  7. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    It may do, but I just did some testing on it, putting the redirect all the way at the bottom, underneath a mountain of php and html all outputting random stuff, and it still managed to redirect without an error.
    So hopefully shouldn't cause too many problems.

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
  •