Jump to content

PAge headers


jimfog
 Share

Recommended Posts

I have read about what page headers are, nonetheless i have never saw them in "action", i mean whenever i have seen a php script(or written) there is not a single clue of them. So, are headers, incorporated "somewhere", not visible with the naked eye? When we develop php applications, should headers be of any concern to us, or is it something that the server "takes care" completely? How can i see code related to page headers in a php script-or this sth that by definition cannot be done? For example, in an index.php file i have never seen code that is related to headers(in anyway)-only the declarations(DOCTYPE...etc), php, html, css(if any). I just need a little help in understanding "what is going on" with the headers.

Link to comment
Share on other sites

Browsers (their "HTTP client" component to be more precise) sees those headers and could allow extensions to look at them and act accordingly. For you to see the headers you're sending/receiving, you need browser add-ons that serve this role. I'd recommend Fiddler (see my signature), as it has a "raw" tab which can quickly give you an "aha" moment - the very thing you see there is EXACTLY what the HTTP clients downloads, except that browsers strip away the headers part out of the "View Source" view. Firebug can also see headers as part of its Net tab, but it displays them in a nice table that makes headers appear as if they're coming out of thin air and placed there.

Link to comment
Share on other sites

When developing in PHP(or other web language), should we take into consideration any details related to the headers(forget for a moment extensions). I am reading a book about php, where at some point,in a code segment of an index.php, the author says,

...preprocessing must be done before headers are sent.
What does that mean?Do you know?
Link to comment
Share on other sites

It's probably specific to that page he was making. I'm not sure why he thinks it should be done that way. It means that you should do all the calculations and data manipulation before sending any headers. Of course, that excludes printing which can't be done before sending headers.

Link to comment
Share on other sites

Ok, i saw the raw tab(under...inspector)...i understood what the headers are. There are 2 thing here that need clarification: First of all the author of the book says "......preprocessing must be done before headers are sent." How can that be, as i know when, when i page is requested from the browser, by definition, the headers are sent first, and then PHP parses the script, unless i am wrong, in which case the above statement needs correction/ The second thing is, why someone would want to go that route? The author does not explain that. Well... i hear what you have to say.

Link to comment
Share on other sites

<div>

How can that be, as i know when, when i page is requested from the browser, by definition, the headers are sent first, and then PHP parses the script, unless i am wrong, in which case the above statement needs correction/
</div><div> </div><div><p>what the author means is sending response header. Their is two type of headers REQUEST header which browser sends when you request a page and another is RESPONSE haeder which send server after processing page.<br /> </p><div><p>
</p></div><div>why someone would want to go that route?</div><p>
</p><p> </p><div><p>There may be any other reason for what the author says that. But there is a practical implementetion of like that which i faced and did before. I was developing a forum and there i need to change the title and meta tags on each page depending upon the data. There is also another reason if you deal with headers(). the most common redirecting header error is for that reason "Header already been sent" same with cookies also. (Though there is output buffering for workaround this) So that proccesing has done first and after that headers sent to the browser for display.</p></div></div>
Link to comment
Share on other sites

The headers are not automatically sent immediately, all headers are sent by PHP the first time you send any output to the browser. Since headers go before the body, the first time you send any output then PHP will send all headers. You can't send more headers after that. You can use the headers_sent function to check if they were already sent.

Link to comment
Share on other sites

First of all the author of the book says "......preprocessing must be done before headers are sent." How can that be, as i know when, when i page is requested from the browser, by definition, the headers are sent first, and then PHP parses the script, unless i am wrong, in which case the above statement needs correction/ The second thing is, why someone would want to go that route? The author does not explain that.
Headers won't be sent first unless you send them first. Because once you send output to the page, like echo, you can't use something like header(). it is also more mangeable to do all your calculations up front in one place where it is easier to keep track of, and then use your HTML like a template where you can plug in your processed data. So do that first, build your template/output, then display it.
Link to comment
Share on other sites

Headers won't be sent first unless you send them first. Because once you send output to the page, like echo, you can't use something like header(). it is also more mangeable to do all your calculations up front in one place where it is easier to keep track of, and then use your HTML like a template where you can plug in your processed data. So do that first, build your template/output, then display it.
ian getting the picture(more or less)-as I understand it preprocessing is done for organizational purposes.am I correct to assume that it could be done also in the code segment that prints to the browser-an alternative strategy?
Link to comment
Share on other sites

As soon as you start to actually output content (as in "not headers"), you can't send headers anymore.However, you can have echoes, and suppress the actual content outputting until you explicitly demand it with ob_flush(). During the suppression, you can send headers. This practice is not recommended however, as output buffering could be disabled on a server and/or lead to poorer performance if not used wisely (conversely, it could improve the apparent performance if used wisely).

Link to comment
Share on other sites

I know what I might say now might take this post in a different direction and come to realize that what we have said till now prove to be based on the wrong assumption,I am going to say it though.it seems that the author when he mentions "headers" he does not mean HTML headers(doctype etc) but instead he refers to page header from a design standpoint-the top portion of a webpageI think that things make more sense now.

Link to comment
Share on other sites

What he mean is HTTP header. neither the html header (head tag, doctype) nor the header from design prespective. You are stil missing the point. You may like to read the above answers again.

Link to comment
Share on other sites

You may like to read the above answers again.
Will do
Link to comment
Share on other sites

I know what I might say now might take this post in a different direction and come to realize that what we have said till now prove to be based on the wrong assumption,I am going to say it though. it seems that the author when he mentions "headers" he does not mean HTML headers(doctype etc) but instead he refers to page header from a design standpoint-the top portion of a webpage I think that things make more sense now.
you need to remember your context. You are reading a book about PHP. PHP and HTTP headers are related and makes more sense, and so that is what the author is talking about. If you were reading an HTML/CSS book, then headers referring to page design and layout would make sense. http://en.wikipedia....iki/HTTP_header Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...