Header Location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    Header Location

    Its not a php Question. Its a HTTP question

    how web server send client Location header request.

    The thing is, after sending "\r\n\r\n" web server start to send data to web client but even though in that situation if we create a Location header request it works
    look at the below example.
    Code:
    <?php
    echo "johny";
    header("Location: request.php");
    ?>
    How it works?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I don't understand your question; but I am pretty sure your piece of code will fail with a 'headers already sent' error

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      That is the point. This code dont return error. More over it redirected by browser perfectly.

      this is the out put i get from a small http client i have made

      HTTP/1.1 302 Found
      Date: Mon, 16 Aug 2010 08:49:57 GMT
      Server: Apache/2.2.11 (Win32) PHP/5.2.8
      X-Powered-By: PHP/5.2.8
      Location: request.php
      Content-Length: 37
      Connection: close
      Content-Type: text/html

      johny

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        I have just made a test


        Code:
        <?php
         echo "I am johny\n"; 
         setcookie("Log_time", time()); //according to my previous knowledge it was not suppose to work
        ?>
        the output is

        HTTP/1.1 200 OK
        Date: Mon, 16 Aug 2010 09:06:50 GMT
        Server: Apache/2.2.11 (Win32) PHP/5.2.8
        X-Powered-By: PHP/5.2.8
        Set-Cookie: Log_time=128194 9610
        Content-Length: 11
        Connection: close
        Content-Type: text/html

        I am johny


        now i can guess its a version issue. Now PHP do not send data directly to client. First it create output then send it to client. that is why it does not create any warning. But I can guess older version make this warning.

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          I thought this was only possible with output buffering turned on.
          Is it turned on by default in your version?
          Take a look at the php.ini file

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            for the client it doesn’t matter if there is content or not. the Location header directive just states that the the client has to load the specified URI.

            Comment

            • johny10151981
              Top Contributor
              • Jan 2010
              • 1059

              #7
              @code_green
              in that case this is the fact. In my case output buffering is on.
              I didnt change the configuration. it was default

              Directive Local Value Master Value
              output_bufferin g 4096 4096


              I got my answer, I think.

              @Dormilich:
              The entire issue started while i was answering one persons question about header warning. When I tested it in my page with Location directive it was not making any warning. So I made a c code to check what server give to client. Then i figured out that the header part is in header part even though i already have sent the out data. So I was confused how it work. :) now i got my answer

              Comment

              Working...