SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question about header('Location: xxxxx')

    is there a difference between these 2?

    PHP Code:
    header('Location: http://www.domain.com/file.php'); 
    PHP Code:
    header('Location: file.php'); 
    i thought i read about there being a difference but i don't know. will they both work the same? does it depend on the server?
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    file.php will redirect to file.php in the current directory, whereas 'Location: http://www.domain.com/file.php' will force the servername and directory. They should both work on your server.
    ck :: bringing chris to the masses.

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i understand that you use the full URL when you want to redirect to another site. i guess i wasn't clear.

    i mean, though, if i want to redirect to file.php on my site, in the same directory, is there a difference between just saying "file.php" and using the full URL?

    the thing i thought i read is that Apache would handle it differently. like if you just put the file it would just send out the contents of the new file and not actually redirect the browser (i.e. the address bar doesn't change). although on my Win/Apache system here they both seem to work the same (redirecting). but i want to know for sure.

  4. #4
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that they both work the same. One just saves you typing (if you don't want to externally redirect). With header("Location: file") the address bar changes (at least for me on several pcs). I hope that answers your question.
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  5. #5
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is another difference.

    Let's say you go http://www.company.com/dir/test.php

    This page has a header redirect that sends your test2.php in the the same directory. If you only give the file name in the header location, you'll be redirected to test2.php but your address bar will still show test.php. If you give the full url, the address bar will change to show test2.php.

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, CyberFuture, that's what i thought i read. it's like Apache requests the page itself (a sub-request like in SSI), and that's why the address bar wouldn't change. BUT my results have been like kcabobert's and the addy does change.

    i wonder if it IS a server thing w/ the way Apache handles it or if it's a browser thing that decides whether to update the address bar.

    so i dunno...


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
  •