Jump to content

What Is A Header?


skaterdav85

Recommended Posts

They are part of the HTTP specification. Headers include all of the metadata for the request and response. When the browser sends a request the headers include things like the browser's user agent string, the content types the browser will accept, compression types the browser will accept, languages it will accept, etc, in addition to the URL it's looking for on the server. The response headers from the server will include things like the response code (e.g., 200, 404, 500, etc), the server time, information about software on the server (most servers by default will identify themselves as either IIS or Apache, some include the version of PHP or ASP, etc), the content type of the response, the length of the response, etc.Basically, headers are the entirety of HTTP communication except for the post data which a browser sends for a form, or the response data the server sends back (the actual HTML or image data, etc). Everything else is a header. You can look through the HTTP spec for a list of all request and response headers.

Link to comment
Share on other sites

$session = curl_init('someurl.com');curl_setopt($session, CURLOPT_RETURNTRANSFER, true);$remoteFile = curl_exec($session);

In this code, does the curl_exec() function return the response data as well as the response headers in one big string? But if I set the CURLOPT_HEADER option to false like this:

curl_setopt($session, CURLOPT_HEADER, false);

, curl_exec will only return the response data in a string?

Link to comment
Share on other sites

$session = curl_init('someurl.com');curl_setopt($session, CURLOPT_RETURNTRANSFER, true);$remoteFile = curl_exec($session);

In this code, does the curl_exec() function return the response data as well as the response headers in one big string? But if I set the CURLOPT_HEADER option to false like this:

curl_setopt($session, CURLOPT_HEADER, false);

, curl_exec will only return the response data in a string?

I think that's about right. Why not var_dump($remoteFile) and find out yourself?
Link to comment
Share on other sites

well i did do a print_r and a var_dump and all i see is the source code of the url that i sent to curl. Although with var_dump, I did get back the string(1054). How would I know if I got back headers or not?
If the very first line of a var_dump() (after the type and length that is) is something like
HTTP/1.1 200 OK

Then you likely also have the headers.

Link to comment
Share on other sites

is it possible to create your own header data for a request and retrieve it, kind of like if you are doing a form submission using post or get?
Yes. You can define your own headers in both the request and the response. If in the request, the server must "support" the header if it is going to do anything with it. If in the response, the client must "support" the header if it is going to do anything with it.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...