Solved

How to Identify HTTP headers?

Posted on 2010-09-19
8
679 Views
Last Modified: 2012-05-10
Hello:

I am using PHP / CURL to open a remote URL.

All works fine. However, I want to identify what HEADERS are sent when I am requesting a particular URL using PHP/CURL? Also, i would like to capture the HEADERS which are received back with the URL.

Any examples?
0
Comment
Question by:nainil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 125 total points
ID: 33713864
Hello nainil,

Following are some links that might help you. Please check them out.

http://php.net/manual/en/ref.curl.php

http://it.toolbox.com/wiki/index.php/Use_curl_from_PHP_-_processing_response_headers

http://www.bigresource.com/Tracker/Track-php-1OSr9l3e/

Hopefully it will help you.

Thanks.
0
 

Author Comment

by:nainil
ID: 33716241
amar_bardoliwala: Thanks.

However, I was looking for something different. May be I did not frame my question correctly.

I am not setting any HEADERS before requesting a page through CURL. So, apparently, some default headers are being sent and returned.

My task is to identify WHAT headers are sent while requesting a URL through CURL.

Hope it helps!
0
 

Author Comment

by:nainil
ID: 33716589
Also that information would linclude Useragent etc which is being sent.
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Expert Comment

by:Coryf88
ID: 33731364

$ch = curl_init('http://www.google.com');

curl_setopt_array($ch, array(
	CURLOPT_RETURNTRANSFER	=> TRUE,
	CURLOPT_HEADER			=> TRUE,
	CURLINFO_HEADER_OUT		=> TRUE,
));

list($response_headers, $response_body) = explode("\r\n\r\n", curl_exec($ch), 2);
$info = curl_getinfo($ch);
curl_close($ch);

var_dump($info['request_header'], $response_headers, $response_body);

Open in new window

0
 
LVL 15

Assisted Solution

by:samri
samri earned 125 total points
ID: 33755455
Here is the plain HTTP GET Request from CURL (WinXP)
Curl version:
curl 7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
Protocols: dict file ftp ftps http https imap imaps ldap pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS Largefile NTLM SSL SSPI libz

Request:
No.     Time        Source                Destination           Protocol SrcPrt DstPrt Info                                                            DelTme
     16 5.720232    192.168.1.101         64.233.181.105        HTTP     21790  80     GET / HTTP/1.1                                                  0.002500

Frame 16 (189 bytes on wire, 189 bytes captured)
Ethernet II, Src: Intel_28:20:d4 (00:19:d2:28:20:d4), Dst: HewlettP_0d:df:ba (00:11:85:0d:df:ba)
Internet Protocol, Src: 192.168.1.101 (192.168.1.101), Dst: 64.233.181.105 (64.233.181.105)
Transmission Control Protocol, Src Port: 21790 (21790), Dst Port: http (80), Seq: 1, Ack: 1, Len: 135
Hypertext Transfer Protocol
    GET / HTTP/1.1\r\n
     User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3\r\n
    Host: www.google.com\r\n
    Accept: */*\r\n
    \r\n

In brief, the plain get would send the header : User-Agent:, Host:, Accept:



Hope this helps.
0
 

Author Comment

by:nainil
ID: 33802629
samri: can you please advise how you grabbed this HTTP GET request from Curl on Windows?

Was it through PHP or some sniffer?
0
 

Author Comment

by:nainil
ID: 34213026
Closing the question.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question