question on header() function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JRough

    question on header() function

    What is the purpose of caching in the header below? I used
    something like this for downloading a detail page to Excel but in this
    example it looks like it is for cache control? Why would you expire a
    header? So the user couldn't send a request after too long of a period
    for example in the downloaded excel page?


    <?php
    header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the
    past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    // always
    modified
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/
    1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache"); // HTTP/1.0
    ?>

    Also, what is the status header for or rather how does it work? You
    can get some status information from the server? Is this sent in
    conjunction with a header request? What is not found the page or the
    server?

    header(“Status: 404 Not Found”);

    thanks,
  • 703designs

    #2
    Re: question on header() function

    On Nov 10, 10:47 pm, JRough <jlro...@yahoo. comwrote:
    What is the purpose of caching in the header below?    I used
    something like this for downloading a detail page to Excel but in this
    example it looks like it is for cache control?  Why would you expire a
    header? So the user couldn't send a request after too long of a period
    for example in the downloaded excel page?
    >
    <?php
    header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the
    past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                         // always
    modified
    header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/
    1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");                          // HTTP/1.0
    ?>
    >
    Also, what is the status header for or rather how does it work?  You
    can get some status information from the server?  Is this sent in
    conjunction with a header request?  What is not found the page or the
    server?
    >
    header(“Status:  404 Not Found”);
    >
    thanks,
    Take this with a small grain of salt; I'm not an HTTP expert.

    I'd expect that you'd use a far-past Expires header to ensure that the
    browser downloads the most recent resources. As for the 404, that
    means the resource is not found on the server. If the server were not
    found, you couldn't connect to the site.

    Thomas

    Comment

    • JRough

      #3
      Re: question on header() function

      On Nov 10, 8:12 pm, 703designs <thomasmal...@g mail.comwrote:
      On Nov 10, 10:47 pm, JRough <jlro...@yahoo. comwrote:
      >
      >
      >
      What is the purpose of caching in the header below?    I used
      something like this for downloading a detail page to Excel but in this
      example it looks like it is for cache control?  Why would you expire a
      header? So the user couldn't send a request after too long of a period
      for example in the downloaded excel page?
      >
      <?php
      header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the
      past
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                          // always
      modified
      header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/
      1.1
      header("Cache-Control: post-check=0, pre-check=0", false);
      header("Pragma: no-cache");                         // HTTP/1.0
      ?>
      >
      Also, what is the status header for or rather how does it work?  You
      can get some status information from the server?  Is this sent in
      conjunction with a header request?  What is not found the page or the
      server?
      >
      header(“Status:  404 Not Found”);
      >
      thanks,
      >
      Take this with a small grain of salt; I'm not an HTTP expert.
      >
      I'd expect that you'd use a far-past Expires header to ensure that the
      browser downloads the most recent resources. As for the 404, that
      means the resource is not found on the server. If the server were not
      found, you couldn't connect to the site.
      >
      Thomas
      but I don't understand when you use the status header. Do you use it
      before you use a header location call? Also what is the boolean
      replace in the header for? I'm just trying
      to understand the in's and out's of header() function. What do you
      use the caching for are there other instances than for downloading as
      a pdf or excel content type?

      Comment

      • 703designs

        #4
        Re: question on header() function

        You use caching to make pages load faster and to lighten the server
        load. On the user end, a cached page loads nearly instantly (the HTML
        and other resources are already on the user's computer). You can cache
        your pages on the server side too. Let's say I have a very complex
        script that returns 100 user records and all sorts of other mumbo-
        jumbo. That page may take a while to build, but if it's cached, it
        doesn't need to be built (the generated page is ready on the server).
        The drawback is that you will not see any changes made to the page
        after the cache is built (until it's rebuilt).

        Status codes are very important in HTTP: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

        404 is "not found." 200 is "found." And there are many others
        (permanently relocated, temporarily relocated, etc.).

        I'm not sure what you mean by "boolean replace."

        Thomas

        On Nov 10, 11:15 pm, JRough <jlro...@yahoo. comwrote:
        On Nov 10, 8:12 pm, 703designs <thomasmal...@g mail.comwrote:
        >
        >
        >
        On Nov 10, 10:47 pm, JRough <jlro...@yahoo. comwrote:
        >
        What is the purpose of caching in the header below?    I used
        something like this for downloading a detail page to Excel but in this
        example it looks like it is for cache control?  Why would you expire a
        header? So the user couldn't send a request after too long of a period
        for example in the downloaded excel page?
        >
        <?php
        header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the
        past
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                             // always
        modified
        header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/
        1.1
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");                          // HTTP/1.0
        ?>
        >
        Also, what is the status header for or rather how does it work?  You
        can get some status information from the server?  Is this sent in
        conjunction with a header request?  What is not found the page or the
        server?
        >
        header(“Status:  404 Not Found”);
        >
        thanks,
        >
        Take this with a small grain of salt; I'm not an HTTP expert.
        >
        I'd expect that you'd use a far-past Expires header to ensure that the
        browser downloads the most recent resources. As for the 404, that
        means the resource is not found on the server. If the server were not
        found, you couldn't connect to the site.
        >
        Thomas
        >
        but I don't understand when you use the status header.  Do you use it
        before you use a header location call?  Also what is the boolean
        replace in the header for?  I'm just trying
        to understand the in's and out's of header() function.  What do you
        use the caching for are there other instances than for downloading as
        a pdf or excel content type?

        Comment

        • Gordon Burditt

          #5
          Re: question on header() function

          >What is the purpose of caching in the header below? I used
          >something like this for downloading a detail page to Excel but in this
          >example it looks like it is for cache control? Why would you expire a
          >header? So the user couldn't send a request after too long of a period
          >for example in the downloaded excel page?
          Generally, headers like this encourage a browser to get UP-TO-DATE
          dynamic content from the server, as distinguished from old data in
          its cache.
          ><?php
          >header("Expire s: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the
          >past
          >header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
          // always
          >modified
          >header("Cach e-Control: no-store, no-cache, must-revalidate"); // HTTP/
          >1.1
          >header("Cach e-Control: post-check=0, pre-check=0", false);
          >header("Pragma : no-cache"); // HTTP/1.0
          >?>
          >
          >Also, what is the status header for or rather how does it work? You
          >can get some status information from the server?
          Yes. There are several types of errors that can be returned (page
          not found, page moved temporarily, page moved permanently, access
          denied, page found OK, etc.) Certain status codes encourage the
          browser to try again with a different URL, or to ask the user for
          authentication information and resubmit the request.
          >Is this sent in
          >conjunction with a header request? What is not found the page or the
          >server?
          This header is being sent FROM THE SERVER. Do you think it is
          likely that the server will send an error code that the server
          wasn't found?
          >header(“Status : 404 Not Found”);

          Comment

          • Jerry Stuckle

            #6
            Re: question on header() function

            JRough wrote:
            On Nov 10, 8:12 pm, 703designs <thomasmal...@g mail.comwrote:
            >On Nov 10, 10:47 pm, JRough <jlro...@yahoo. comwrote:
            >>
            >>
            >>
            >>What is the purpose of caching in the header below? I used
            >>something like this for downloading a detail page to Excel but in this
            >>example it looks like it is for cache control? Why would you expire a
            >>header? So the user couldn't send a request after too long of a period
            >>for example in the downloaded excel page?
            >><?php
            >>header("Expir es: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the
            >>past
            >>header("Las t-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
            >> // always
            >>modified
            >>header("Cac he-Control: no-store, no-cache, must-revalidate"); // HTTP/
            >>1.1
            >>header("Cac he-Control: post-check=0, pre-check=0", false);
            >>header("Pragm a: no-cache"); // HTTP/1.0
            >>?>
            >>Also, what is the status header for or rather how does it work? You
            >>can get some status information from the server? Is this sent in
            >>conjunction with a header request? What is not found the page or the
            >>server?
            >>header(“Statu s: 404 Not Found”);
            >>thanks,
            >Take this with a small grain of salt; I'm not an HTTP expert.
            >>
            >I'd expect that you'd use a far-past Expires header to ensure that the
            >browser downloads the most recent resources. As for the 404, that
            >means the resource is not found on the server. If the server were not
            >found, you couldn't connect to the site.
            >>
            >Thomas
            >
            but I don't understand when you use the status header. Do you use it
            before you use a header location call? Also what is the boolean
            replace in the header for? I'm just trying
            to understand the in's and out's of header() function. What do you
            use the caching for are there other instances than for downloading as
            a pdf or excel content type?
            Every HTTP request sends a status. 200 is normal; 404 is Not Found.
            There are a bunch of them, each with its own purpose. To get a list of
            the valid status codes, google for

            HTTP Status.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • JRough

              #7
              Re: question on header() function

              On Nov 10, 8:23 pm, gordonb.a5...@b urditt.org (Gordon Burditt) wrote:
              What is the purpose of caching in the header below?    I used
              something like this for downloading a detail page to Excel but in this
              example it looks like it is for cache control?  Why would you expire a
              header? So the user couldn't send a request after too long of a period
              for example in the downloaded excel page?
              >
              Generally, headers like this encourage a browser to get UP-TO-DATE
              dynamic content from the server, as distinguished from old data in
              its cache.
              >
              <?php
              header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the
              past
              header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                                 // always
              modified
              header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/
              1.1
              header("Cache-Control: post-check=0, pre-check=0", false);
              header("Pragma: no-cache");                          // HTTP/1.0
              ?>
              >
              Also, what is the status header for or rather how does it work?  You
              can get some status information from the server?  
              >
              Yes.  There are several types of errors that can be returned (page
              not found, page moved temporarily, page moved permanently, access
              denied, page found OK, etc.)  Certain status codes encourage the
              browser to try again with a different URL, or to ask the user for
              authentication information and resubmit the request.
              >
              Is this sent in
              conjunction with a header request?  What is not found the page or the
              server?
              >
              This header is being sent FROM THE SERVER.  Do you think it is
              likely that the server will send an error code that the server
              wasn't found?
              >
              header(“Status:  404 Not Found”);
              >
              >
              thanks, so the cache is in the browser page displayed and if the data
              changed it would get more recent data than the expired data on the
              page unless you wanted the user to download the same data as what he
              originally saw on the page. In any case it is the veriation in the
              data at that moment in time viewed by the user and some other later
              date in case
              he leaves his browser open for awhile then decides to download the
              data later.

              What is the boolean replace function for in the header function?

              thanks

              Comment

              • Jerry Stuckle

                #8
                Re: question on header() function

                JRough wrote:
                On Nov 10, 8:23 pm, gordonb.a5...@b urditt.org (Gordon Burditt) wrote:
                >>What is the purpose of caching in the header below? I used
                >>something like this for downloading a detail page to Excel but in this
                >>example it looks like it is for cache control? Why would you expire a
                >>header? So the user couldn't send a request after too long of a period
                >>for example in the downloaded excel page?
                >Generally, headers like this encourage a browser to get UP-TO-DATE
                >dynamic content from the server, as distinguished from old data in
                >its cache.
                >>
                >><?php
                >>header("Expir es: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the
                >>past
                >>header("Las t-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                >> // always
                >>modified
                >>header("Cac he-Control: no-store, no-cache, must-revalidate"); // HTTP/
                >>1.1
                >>header("Cac he-Control: post-check=0, pre-check=0", false);
                >>header("Pragm a: no-cache"); // HTTP/1.0
                >>?>
                >>Also, what is the status header for or rather how does it work? You
                >>can get some status information from the server?
                >Yes. There are several types of errors that can be returned (page
                >not found, page moved temporarily, page moved permanently, access
                >denied, page found OK, etc.) Certain status codes encourage the
                >browser to try again with a different URL, or to ask the user for
                >authenticati on information and resubmit the request.
                >>
                >>Is this sent in
                >>conjunction with a header request? What is not found the page or the
                >>server?
                >This header is being sent FROM THE SERVER. Do you think it is
                >likely that the server will send an error code that the server
                >wasn't found?
                >>
                >>header(“Statu s: 404 Not Found”);
                >>
                thanks, so the cache is in the browser page displayed and if the data
                changed it would get more recent data than the expired data on the
                page unless you wanted the user to download the same data as what he
                originally saw on the page. In any case it is the veriation in the
                data at that moment in time viewed by the user and some other later
                date in case
                he leaves his browser open for awhile then decides to download the
                data later.
                >
                What is the boolean replace function for in the header function?
                >
                thanks
                No, the cache is in the browser. The page cannot cache itself.

                Also, it doesn't matter if the browser is left open or not. Cache can
                also be stored on disk and used even after you reboot.

                As to the replace parameter - from the manual:

                "The optional replace parameter indicates whether the header should
                replace a previous similar header, or add a second header of the same
                type. By default it will replace, but if you pass in FALSE as the second
                argument you can force multiple headers of the same type. "

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • 703designs

                  #9
                  Re: question on header() function

                  On Nov 11, 6:30 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  JRough wrote:
                  On Nov 10, 8:23 pm, gordonb.a5...@b urditt.org (Gordon Burditt) wrote:
                  >What is the purpose of caching in the header below?    I used
                  >something like this for downloading a detail page to Excel but in this
                  >example it looks like it is for cache control?  Why would you expire a
                  >header? So the user couldn't send a request after too long of a period
                  >for example in the downloaded excel page?
                  Generally, headers like this encourage a browser to get UP-TO-DATE
                  dynamic content from the server, as distinguished from old data in
                  its cache.
                  >
                  ><?php
                  >header("Expire s: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the
                  >past
                  >header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                  >                                                    // always
                  >modified
                  >header("Cach e-Control: no-store, no-cache, must-revalidate");  // HTTP/
                  >1.1
                  >header("Cach e-Control: post-check=0, pre-check=0", false);
                  >header("Pragma : no-cache");                          // HTTP/1.0
                  >?>
                  >Also, what is the status header for or rather how does it work?  You
                  >can get some status information from the server?  
                  Yes.  There are several types of errors that can be returned (page
                  not found, page moved temporarily, page moved permanently, access
                  denied, page found OK, etc.)  Certain status codes encourage the
                  browser to try again with a different URL, or to ask the user for
                  authentication information and resubmit the request.
                  >
                  >Is this sent in
                  >conjunction with a header request?  What is not found the page or the
                  >server?
                  This header is being sent FROM THE SERVER.  Do you think it is
                  likely that the server will send an error code that the server
                  wasn't found?
                  >
                  >header(“Status :  404 Not Found”);
                  >
                  thanks, so the cache is in the browser page displayed and if the data
                  changed it would get more recent data than the expired data on the
                  page unless you wanted the user to download the same data as what he
                  originally saw on the page.  In any case it is the veriation in the
                  data at that moment in time viewed by the user and some other later
                  date in case
                  he leaves his browser open for awhile then decides to download the
                  data later.
                  >
                  What is the boolean replace function for in the header function?
                  >
                  thanks
                  >
                  No, the cache is in the browser.  The page cannot cache itself.
                  >
                  Also, it doesn't matter if the browser is left open or not.  Cache can
                  also be stored on disk and used even after you reboot.
                  >
                  As to the replace parameter - from the manual:
                  >
                  "The optional replace parameter indicates whether the header should
                  replace a previous similar header, or add a second header of the same
                  type. By default it will replace, but if you pass in FALSE as the second
                  argument you can force multiple headers of the same type. "
                  >
                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstuck...@attgl obal.net
                  =============== ===
                  Hi JRough,

                  Keep in mind that caching refers to any method of storing a page for
                  future use. It can happen on the server or in the browser in the ways
                  I described earlier. Even more generally, caching refers to storing a
                  resource or series of resources in advance, usually for performance
                  reasons.

                  Just don't want you to take home too narrow of a definition because
                  you will see the term frequently.

                  Thanks,
                  Thomas

                  Comment

                  Working...