Solved

How to Identify HTTP headers?

Posted on 2010-09-19
8
671 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
8 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Also that information would linclude Useragent etc which is being sent.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:Coryf88
Comment Utility

$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
Comment Utility
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
Comment Utility
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
Comment Utility
Closing the question.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now