SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Location rederict

    I'm going crazy. I did this so many times and now it's not working.

    I have this line on a page:
    PHP Code:
    header("Location: $url"); 
    I tried to output the same thing on the page, without the redirect and it outputs what is set in $url.
    But when I write that line, it doesn't redirect. Am I doing something wrong with the " ?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    That looks OK to me. It might be something to do with the larger context. What does happen at the moment? Can you post more code?

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But when I write
    PHP Code:
    <?php echo $url?>
    The url is showing correct on the screen.

    This code is working:
    PHP Code:
    $url $row_rs_band['url'];
    echo 
    $url
    This code is NOT working:
    PHP Code:
    header("Location: $url"); 
    The first thing is a code I placed to check if the output is correct.
    Then when running the second one, I removed the first part, since there cannot be any output before a redirect.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I have no idea what I did now. I just wrote the code, uploaded the file and now it works.
    Maybe an invisible space was inserted. Sometimes I've seen that when copying and pasting...

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Two things to watch out for with header();

    Do not output anything prior to calling it, not a space, new line, nothing.

    call
    PHP Code:
    exit(); 
    on the line immediately below.

    Turn on error_reporting when you spot this again.

    OK, thats 3 things ...


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
  •