Documents

Code.tutsplus.com-HTTP Headers for Dummies

Description
Tutsplus tutorial
Categories
Published
of 21
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  HTTP Headers for Dummies code.tutsplus.com /tutorials/http-headers-for-dummies--net-8039Whether you're a programmer or not, you have seen it everywhere on the web. At this moment your browsers address bar shows something that starts with http:// . Even your first Hello World script sentHTTP headers without you realizing it. In this article we are going to learn about the basics of HTTPheaders and how we can use them in our web applications. What are HTTP Headers? HTTP stands for Hypertext Transfer Protocol . The entire World Wide Web uses this protocol. It wasestablished in the early 1990's. Almost everything you see in your browser is transmitted to your computer over HTTP. For example, when you opened this article page, your browser probably havesent over 40 HTTP requests and received HTTP responses for each.HTTP headers are the core part of these HTTP requests and responses, and they carry informationabout the client browser, the requested page, the server and more. Example When you type a url in your address bar, your browser sends an HTTP request and it may look likethis:  GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1Host: net.tutsplus.comUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveCookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120Pragma: no-cacheCache-Control: no-cache First line is the Request Line which contains some basic info on the request. And the rest are theHTTP headers. After that request, your browser receives an HTTP response that may look like this: HTTP/1.x 200 OKTransfer-Encoding: chunkedDate: Sat, 28 Nov 2009 04:36:25 GMTServer: LiteSpeedConnection: closeX-Powered-By: W3 Total Cache/0.8Pragma: publicExpires: Sat, 28 Nov 2009 05:36:25 GMTEtag: pub1259380237;gz Cache-Control: max-age=3600, publicContent-Type: text/html; charset=UTF-8Last-Modified: Sat, 28 Nov 2009 03:50:37 GMTX-Pingback: http://net.tutsplus.com/xmlrpc.phpContent-Encoding: gzipVary: Accept-Encoding, Cookie, User-Agent<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ><html xmlns= http://www.w3.org/1999/xhtml ><head><meta http-equiv= Content-Type content= text/html; charset=utf-8 /><title>Top 20+ MySQL Best Practices - Nettuts+</title><!-- ... rest of the html ... --> The first line is the Status Line , followed by HTTP headers , until the blank line. After that, the content starts (in this case, an HTML output).When you look at the source code of a web page in your browser, you will only see the HTML portionand not the HTTP headers, even though they actually have been transmitted together as you seeabove.These HTTP requests are also sent and received for other things, such as images, CSS files,JavaScript files etc. That is why I said earlier that your browser has sent at least 40 or more HTTPrequests as you loaded just this article page.Now, let's start reviewing the structure in more detail. How to See HTTP Headers  I use the following Firefox extensions to analyze HTTP headers:FirebugLive HTTP Headers  In PHP:getallheaders() gets the request headers. You can also use the $_SERVER array.headers_list() gets the response headers.Further in the article, we will see some code examples in PHP. HTTP Request Structure
Search
Tags
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks