473,770 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,
Nov 11 '08 #1
8 1660
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
Nov 11 '08 #2
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?
Nov 11 '08 #3
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?
Nov 11 '08 #4
>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”);
Nov 11 '08 #5
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.
js*******@attgl obal.net
=============== ===
Nov 11 '08 #6
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
Nov 11 '08 #7
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.
js*******@attgl obal.net
=============== ===
Nov 11 '08 #8
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
Nov 11 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4443
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg second.php) with the header("Location:") function. second.php doesn't either send any output to the browser. The browser is then send to another page also with the header() function. Now my problem: I have to send user and password data...
17
6646
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products. So I shall have an Abstract Base called 'Car' implemented by Toyota, Ford, and Buick. Further I'd like to enable to client to say Car *factory;
4
1821
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at compile time, definitions of these functions, unlike other definitions, cannot be separately compiled and must be placed in header files. This creates a problem if the compiler does not actually inline a
55
2797
by: ben | last post by:
is it true that a function without an inline keyword never get inlined? If not true when is it inlined or not? ben
36
2285
by: Martin Andert | last post by:
Hello, I have a question regarding malloc and free. Here my code sample: int main() { /* allocating dynamic memory for array */ int* array = (int*) malloc(5 * sizeof(int)); /* ... program code ... */
53
4093
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
7
2168
by: somenath | last post by:
Hi All , As a process of my C language learning I was trying to learn how malloc can be implemented from K&R2 .But I am not able to understand few points . It would be very much helpful if some body give some inputs in the bellow mentioned points. Point 1) I page 186 it is said that "In malloc, the requested size in characters is rounded up to the proper number of header-sized units; the block that will be allocated contains one...
12
3018
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
4
1673
by: Immortal_Nephi | last post by:
You have written several global functions inside header code. Then, you create either static library or dynamic linked library. All global functions can be reuseable to the main() function when you include header code. One problem is that you have created one function. You want to place it in the main's source code. You may not want to move it back to the header code. The C++ Compiler will compile and link without any problems if...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.