<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rahul Vaidya's Blog &#187; javascript</title>
	<atom:link href="http://www.rvaidya.com/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rvaidya.com/blog</link>
	<description>Development, Tech, Whatever.</description>
	<lastBuildDate>Wed, 16 Sep 2009 00:33:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Get request headers sent by client in PHP</title>
		<link>http://www.rvaidya.com/blog/php/2009/02/25/get-request-headers-sent-by-client-in-php/</link>
		<comments>http://www.rvaidya.com/blog/php/2009/02/25/get-request-headers-sent-by-client-in-php/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 08:56:31 +0000</pubDate>
		<dc:creator>Rahul</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://www.rvaidya.com/blog/?p=36</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>A nice little function I found posted by &#8220;lazynitwit&#8221; on BlueHost forums:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li><span style="color: #000000; font-weight: bold;">function</span> getHeaders<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></li><li><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;HTTP_&quot;</span><span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #339933;">,</span> 5<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #000088;">$headers</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span>&nbsp;&nbsp;</li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>The PHP function getallheaders() only works on Apache, and only if Apache has been installed as a module.</p>
<p>It turns out that this information is within the $_SERVER global variable, and can be parsed out.</p>
<p>This code is useful if, for instance, you want to differentiate between user browser requests and requests made through AJAX.  Some of the JavaScript frameworks (jQuery, Prototype, YUI, MooTools) send a special header,</p>
<p>X-Requested-With: XMLHttpRequest</p>
<p>whenever a request is made.  I have put this to use in my <a href="http://www.rvaidya.com/chat?channels=test">phpFreeChat chat box</a> to allow channels to be specified in the URL as GET parameters.</p>
<p>via <a href="http://www.bluehostforum.com/showthread.php?t=1453">request headers  php  &#8211; bluehostforum.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rvaidya.com/blog/php/2009/02/25/get-request-headers-sent-by-client-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
