Results 1 to 4 of 4

Thread: Header Redirect With PHP

  1. #1
    Junior Member
    Join Date
    Jul 2003
    Posts
    24

    Header Redirect With PHP

    I'v been reading information about browser redirections using PHP, i have noticed
    some sites saying that using a header command like
    PHP Code:
    header("Location: page.html"); 
    is enough, while on other community sites people say no, it is better to use the following snippet of code, which does the same job ...

    PHP Code:
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: page.html");
    header("Connection: close"); 
    will you please try discussing this here, effects on browser, server, server load, page process time, load time and other aspects ?? which is in yourpoint of view, is better !!!

    Thanks in advance...
    Ruslan K. Abu Zant
    eReg(c) Internet Services
    http://ereg.info/ | http://gold-directory.com/ | http://xui.info/

  2. #2
    Senior Member
    Join Date
    Aug 2001
    Posts
    100
    if you redirect with php the status is set to REDIRECT 302 inless you have already set status like in your code. (see php manual)
    your code should produce a server responce like this:
    <--snip-->
    Server Response: http://www.mydomain.com
    Status: HTTP/1.1 302 Found
    Date: Wed, 18 Jun 2003 22:04:36 GMT
    Server: Apache/1.3.27 (Unix) mod_log_bytes/1.2 mod_bwlimited/1.0 php/4.3.1 FrontPage/5.0.2.2510 mod_ssl/2.8.14 OpenSSL/0.9.6b
    X-Powered-By: php/4.3.1
    Status: HTTP/1.1 301 moved permanently
    Location: http://www.mydomain.com/mydir
    Keep-Alive: timeout=15, max=100
    Connection: Close
    Transfer-Encoding: chunked
    Content-Type: text/html
    <--snap-->
    on the client site for your browser there should be no effects (except from the redirecting action) and i don't think page process time is much bigger if you use the second code.
    \"Knowledge is the Real Power\"

  3. #3
    Junior Member
    Join Date
    Jul 2003
    Posts
    24
    thanks 4 d answer, listening 4 more....
    Ruslan K. Abu Zant
    eReg(c) Internet Services
    http://ereg.info/ | http://gold-directory.com/ | http://xui.info/

  4. #4
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    Actually, you should specify an absolute URL when sending Location: headers to the browser, e.g.

    PHP Code:
    header('Location: page.html'); // is technically incorrect 
    PHP Code:
    header('Location: [url]http://www.mysite.com/page.html[/url]'); // the right way to do it 
    Whether or not you include the other lines is up to you, however in my experience the server does this for you and so there is no need to add them manually.
    Paul Waring - Web site design and development.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •