<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Boolean Island !</title>
	<atom:link href="http://ranacse05.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ranacse05.wordpress.com</link>
	<description>Think Binary.</description>
	<pubDate>Tue, 08 Jul 2008 19:40:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Get the Row Number in PDO</title>
		<link>http://ranacse05.wordpress.com/2008/07/08/get-the-row-number-in-pdo/</link>
		<comments>http://ranacse05.wordpress.com/2008/07/08/get-the-row-number-in-pdo/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 19:40:00 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[PDO]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[row number in PDO]]></category>

		<category><![CDATA[rowCount()]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=82</guid>
		<description><![CDATA[I was working on PHP Data Object (PDO) . But i saw that PDOstatement::rowCount()  does not return row number for mysql when u use the SELECT command . Then i found this function to get the row number after a SELECT query .
&#60;?
function getRowCount($sql)
{
$sql = trim($sql);
$sql = preg_replace(&#8217;~^SELECT\s.*\sFROM~s&#8217;, &#8216;SELECT COUNT(*) FROM&#8217;,
$sql);
$sql = preg_replace(&#8217;~ORDER\s+BY.*?$~sD&#8217;, &#8221;, $sql);
$stmt [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was working on PHP Data Object (PDO) . But i saw that PDOstatement::rowCount()  does not return row number for mysql when u use the SELECT command . Then i found this function to get the row number after a SELECT query .</p>
<p><span style="color:#008000;">&lt;?<br />
function getRowCount($sql)<br />
{<br />
$sql = trim($sql);<br />
$sql = preg_replace(&#8217;~^SELECT\s.*\sFROM~s&#8217;, &#8216;SELECT COUNT(*) FROM&#8217;,<br />
$sql);<br />
$sql = preg_replace(&#8217;~ORDER\s+BY.*?$~sD&#8217;, &#8221;, $sql);<br />
$stmt = $dbh-&gt;query($sql);<br />
$r = $stmt-&gt;fetchColumn(0);<br />
$stmt-&gt;closeCursor();<br />
return $r;<br />
}<br />
?&gt;</span></p>
<p>Now call it like this</p>
<p><span style="color:#008000;">$sql = &#8220;SELECT name,email FROM user where userid=&#8217;$id&#8217; &#8220;;<br />
$totalBooks = getRowCount($sql);</span></p>
<p>This will return the effected row after the SELECT command .</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/82/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/82/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=82&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/07/08/get-the-row-number-in-pdo/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>Got new Mobile</title>
		<link>http://ranacse05.wordpress.com/2008/06/30/got-new-mobile-2/</link>
		<comments>http://ranacse05.wordpress.com/2008/06/30/got-new-mobile-2/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 09:52:33 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[Parsonal]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Sony Ericsson K750i]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=81</guid>
		<description><![CDATA[No new post for this month ! I&#8217;m damn busy with my exam so i cant post new topics here.I&#8217;ll be back soon.I just got my new mobile. Its Sony Ericsson k750i.Its not a new model but i love it so much.Few pictures below and the full information about the set is here.

   [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>No new post for this month ! I&#8217;m damn busy with my exam so i cant post new topics here.I&#8217;ll be back soon.I just got my new mobile. Its Sony Ericsson k750i.Its not a new model but i love it so much.Few pictures below and the full information about the set is <a href="http://www.gsmarena.com/sony_ericsson_k750-1090.php">here</a>.<br />
<img src='http://img.gsmarena.com/vv/pics/sonyericsson/sonyericsson-k750-00.jpg' alt='Sony Ericsson K750i' class='aligncenter' /></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/81/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/81/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=81&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/06/30/got-new-mobile-2/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>

		<media:content url="http://img.gsmarena.com/vv/pics/sonyericsson/sonyericsson-k750-00.jpg" medium="image">
			<media:title type="html">Sony Ericsson K750i</media:title>
		</media:content>
	</item>
		<item>
		<title>Bangla Web App</title>
		<link>http://ranacse05.wordpress.com/2008/05/20/bangla-web-app/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/20/bangla-web-app/#comments</comments>
		<pubDate>Tue, 20 May 2008 08:18:32 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[Bangla computing]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[Web Developing]]></category>

		<category><![CDATA[localization]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[Bangla]]></category>

		<category><![CDATA[Unicode based web app]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=80</guid>
		<description><![CDATA[Last day one of my friend came to me.He was facing a problem (he solved later).Here is his problem &#8211;
The Bangla/Unicode data become ?????? in his page.
I&#8217;m gonna tell u today step-by-step what u need to do if u wanna develop Bangla/Unicode based Web App.
#1 .  First make the database with CHARACTER utf8 and [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Last day one of my friend came to me.He was facing a problem (he solved later).Here is his problem &#8211;<br />
The Bangla/Unicode data become ?????? in his page.</p>
<p>I&#8217;m gonna tell u today step-by-step what u need to do if u wanna develop Bangla/Unicode based Web App.</p>
<p>#1 .  First make the database with <span style="color:#008000;">CHARACTER utf8 </span>and <span style="color:#008000;">collation_connection =&#8217;utf8_general_ci&#8217; </span><br />
#2 . Make the Tables with same configuration.<br />
#3 . When u connect the database use following 2 lines just below the <span style="color:#008000;">mysql_select_db()</span></p>
<p><span style="color:#008000;">mysql_query(&#8217;SET CHARACTER SET utf8&#8242;);<br />
mysql_query(&#8221;SET SESSION collation_connection =&#8217;utf8_general_ci&#8217;&#8221;);</span></p>
<p>#4 . Set the META-TAG as <span style="color:#008000;">&#8220;Content-Type: text/html; charset=UTF-8&#8243;</span></p>
<p>Thats it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> u r done.Here is a sample page what will show data from database</p>
<p><span style="color:#008000;">&lt;?<br />
header(&#8217;Content-Type: text/html; charset=UTF-8&#8242;); <span style="color:#ff6600;">//As its php page i dont need the meta-tag so i need to send a header .</span></span></p>
<p><span style="color:#008000;">mysql_connect(&#8217;localhost&#8217;,'xxxxx&#8217;,'xxxxxx&#8217;) or die(&#8217;Error In connection&#8217;);<br />
mysql_select_db(&#8217;test&#8217;) or die(&#8217;Error In connection(DB)&#8217;);</span></p>
<p><span style="color:#008000;">mysql_query(&#8217;SET CHARACTER SET utf8&#8242;);<br />
mysql_query(&#8221;SET SESSION collation_connection =&#8217;utf8_general_ci&#8217;&#8221;);</span></p>
<p><span style="color:#008000;">$re = mysql_query(&#8221;SELECT * FROM test&#8221;) or die(&#8217;Query Problem&#8217;);<br />
while($row = @mysql_fetch_assoc($re))<br />
echo $row['name'].PHP_EOL;<br />
?&gt;</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/80/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/80/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=80&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/20/bangla-web-app/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>phpMyAdmin বাংলায়</title>
		<link>http://ranacse05.wordpress.com/2008/05/16/phpmyadmin-%e0%a6%ac%e0%a6%be%e0%a6%a8/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/16/phpmyadmin-%e0%a6%ac%e0%a6%be%e0%a6%a8/#comments</comments>
		<pubDate>Fri, 16 May 2008 18:59:21 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[Bangla computing]]></category>

		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=79</guid>
		<description><![CDATA[phpMyAdmin এর বাংলা ভার্সন রিলিজ হল । আমি ও জয় কাজটি করলাম । আমি অন্য কাজে ব্যাস্ত থাকায় বেশী সময় দিতে পারিনি । জয় বেশী সময় দিয়েছে । আজ phpMyAdmin থেকে মেইল পেলাম , ওরা ৩য় ভার্সন থেকে phpMyAdmin এর অন্যান্য ভাষার পাশাপাশি বাংলাকে ও রাখবে । কিন্তু যদি কেউ এখনি ব্যাবহার করতে চান তবে [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal"><a href="http://phpmyadmin.net/">phpMyAdmin</a> <span>এর বাংলা ভার্সন রিলিজ হল । আমি ও <a title="Joy" href="http://joycse06.wordpress.com" target="_blank">জয়</a> কাজটি করলাম । আমি অন্য কাজে ব্যাস্ত থাকায় বেশী সময় দিতে পারিনি । জয় বেশী সময় দিয়েছে । আজ phpMyAdmin থেকে মেইল পেলাম , ওরা ৩য় ভার্সন থেকে phpMyAdmin এর অন্যান্য ভাষার পাশাপাশি বাংলাকে ও রাখবে । কিন্তু যদি কেউ এখনি ব্যাবহার করতে চান তবে <a href="http://rana.phpxperts.net/download/bangla.zip" target="_blank">এখান থেকে ডউনলোড</a> করতে পারেন । তবে সেটিং একটু ঝামেলার । প্রথমে ফাইলটি আনজিপ করুন </span><span>bangla-utf-</span><span>8</span><span style="font-family:Vrinda;">.</span><span>inc.php ফাইলটি কপি করে </span><span>phpMyAdmin এর lang ফোল্ডারে পেষ্ট করুন । তারপর </span><span>phpMyAdmin\libraries ফোল্ডারের </span><span>select_lang.lib.php ফাইলটি এডিট করতে হবে । </span><span>Azerbaijani</span> ভাষার নীচে , নীচের লাইনটি যোগ করুন</p>
<blockquote><p>&#8216;bngla-utf-8&#8242;          =&gt; array(&#8217;bn|bangla&#8217;,  &#8216;bangla-utf-8&#8242;, &#8216;bn&#8217;, &#8216;বাংলা&#8217;),</p></blockquote>
<p>ব্যাস কাজ শেষ ।  এবার phpMyAdmin খুলে ভাষা হিসেবে বাংলাকে বাছাই করুন । <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p class="MsoNormal">
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/79/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/79/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=79&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/16/phpmyadmin-%e0%a6%ac%e0%a6%be%e0%a6%a8/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatically Update</title>
		<link>http://ranacse05.wordpress.com/2008/05/14/automatically-update/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/14/automatically-update/#comments</comments>
		<pubDate>Wed, 14 May 2008 09:05:47 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Web Developing]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[Automatically Loading]]></category>

		<category><![CDATA[Automatically Update]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/2008/05/14/automatically-update/</guid>
		<description><![CDATA[Today one of my friend ask me how can he load the data automatically after a few secs . Let me make it clear.He want to do something which will help the user.The user dont have to refresh his/her page.It&#8217;ll refresh and update it self.
For this you need AJAX.Here is a little example of this.I [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today one of my friend ask me how can he load the data automatically after a few secs . Let me make it clear.He want to do something which will help the user.The user dont have to refresh his/her page.It&#8217;ll refresh and update it self.</p>
<p>For this you need AJAX.Here is a little example of this.I used 3 files here.<br />
#1 index.php</p>
<blockquote><p>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=iso-8859-1&#8243; /&gt;<br />
&lt;title&gt;Ajax Auto Update Example&lt;/title&gt;<br />
&lt;script src=&#8221;AJAX.JS&#8221;&gt;&lt;/script&gt;<br />
&lt;style type=&#8221;text/css&#8221;&gt;<br />
&lt;!&#8211;<br />
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}<br />
&#8211;&gt;<br />
&lt;/style&gt;<br />
&lt;/head&gt;</p>
<p>&lt;body onload=&#8221;show()&#8221;&gt;<br />
&lt;table width=&#8221;561&#8243; height=&#8221;174&#8243; border=&#8221;0&#8243; align=&#8221;center&#8221; cellpadding=&#8221;3&#8243; cellspacing=&#8221;2&#8243;&gt;<br />
&lt;tr&gt;<br />
&lt;td height=&#8221;34&#8243;&gt;&lt;div align=&#8221;center&#8221;&gt;&lt;span class=&#8221;style1&#8243;&gt;The Space Below will be update auto. &lt;/span&gt;&lt;/div&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;div id=&#8221;auto&#8221;&gt;&lt;/div&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>#2 ajax.js</p>
<blockquote><p>var xmlHttp</p>
<p>function show()<br />
{</p>
<p>//Show Loading Massage<br />
document.getElementById(&#8221;auto&#8221;).innerHTML=&#8221;&lt;h3 style=\&#8221;color:#FF0000\&#8221;&gt;Loading&#8230;&#8230;&lt;/h3&gt;&#8221;;</p>
<p>xmlHttp=GetXmlHttpObject()<br />
if (xmlHttp==null)<br />
{<br />
alert (&#8221;Your browser does not support AJAX!&#8221;);<br />
return;<br />
}<br />
var url=&#8221;show.php&#8221;;<br />
xmlHttp.onreadystatechange=stateChanged;</p>
<p>//Get the value from show.php page.I use GET method here.You can use what u want GET/POST</p>
<p>xmlHttp.open(&#8221;GET&#8221;,url,true);<br />
xmlHttp.send(null);</p>
<p>//This page will refresh it self after 2 sec.If u chage the value &#8216;2000&#8242; the time will be changed .<br />
setTimeout(&#8217;show()&#8217;,2000);</p>
<p>}</p>
<p>function stateChanged()<br />
{<br />
if (xmlHttp.readyState==4)<br />
{<br />
//Below line show the server responce on the index.php page.<br />
document.getElementById(&#8221;auto&#8221;).innerHTML=xmlHttp.responseText;<br />
}<br />
}</p>
<p>function GetXmlHttpObject()<br />
{<br />
var xmlHttp=null;<br />
try<br />
{<br />
// Firefox, Opera 8.0+, Safari<br />
xmlHttp=new XMLHttpRequest();<br />
}<br />
catch (e)<br />
{<br />
// Internet Explorer<br />
try<br />
{<br />
xmlHttp=new ActiveXObject(&#8221;Msxml2.XMLHTTP&#8221;);<br />
}<br />
catch (e)<br />
{<br />
xmlHttp=new ActiveXObject(&#8221;Microsoft.XMLHTTP&#8221;);<br />
}<br />
}<br />
return xmlHttp;<br />
}</p></blockquote>
<p>#3 show.php</p>
<blockquote>
<p class="MsoNormal">&lt;?php</p>
<p class="MsoNormal">//If u use data from the database use necessery code here.I just show the current BD time in the page.</p>
<p class="MsoNormal">
<p class="MsoNormal">$am=&#8217;AM&#8217;;</p>
<p class="MsoNormal">$time = localtime();</p>
<p class="MsoNormal">$hour = $time[2]+6;</p>
<p class="MsoNormal">if($hour&gt;=12)</p>
<p class="MsoNormal"><span> </span>$am=&#8217;PM&#8217;;</p>
<p class="MsoNormal">$hour%=12;</p>
<p class="MsoNormal">echo &#8220;&lt;h3 style=\&#8221;color:#009900\&#8221;&gt;Now Time is&#8211;$hour:$time[1]:$time[0]-$am&lt;/h3&gt;&#8221;;</p>
<p class="MsoNormal">
<p class="MsoNormal">?&gt;</p>
</blockquote>
<p class="MsoNormal">
<p class="MsoNormal">Note : You can make ur site like <a href="http://www.gopsop.com/">www.gopsop.com</a> and <a href="http://www.crickinfo.com/">www.crickinfo.com</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/78/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/78/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=78&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/14/automatically-update/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>Word Counter By PHP</title>
		<link>http://ranacse05.wordpress.com/2008/05/06/word-counter-by-php/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/06/word-counter-by-php/#comments</comments>
		<pubDate>Tue, 06 May 2008 22:06:43 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[word counter]]></category>

		<category><![CDATA[wordcounter+php]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=72</guid>
		<description><![CDATA[I was reading Hasin Bhai&#8217;s New book Object Oriented Programming with PHP5.In chapter 2 i got a nice example of OOP.Its a word counter.Its a nice tool actually and pretty little too.Here is that example.  
&#60;?
class WordCounter
{
const ASC=1;  //you need not use $ sign before Constants
const DESC=2;
private $words;
function __construct($filename)
{
$file_content = file_get_contents($filename);
$this-&#62;words =
(array_count_values(str_word_count(strtolower
($file_content),1)));
}
public function count($order)
{
if [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was reading Hasin Bhai&#8217;s New book Object Oriented Programming with PHP5.In chapter 2 i got a nice example of OOP.Its a word counter.Its a nice tool actually and pretty little too.Here is that example. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="color:#008000;">&lt;?<br />
class WordCounter<br />
{<br />
const ASC=1;  //you need not use $ sign before Constants<br />
const DESC=2;<br />
private $words;<br />
function __construct($filename)<br />
{<br />
$file_content = file_get_contents($filename);<br />
$this-&gt;words =<br />
(array_count_values(str_word_count(strtolower<br />
($file_content),1)));<br />
}<br />
public function count($order)<br />
{<br />
if ($order==self::ASC)<br />
asort($this-&gt;words);<br />
else if($order==self::DESC)<br />
arsort($this-&gt;words);<br />
foreach ($this-&gt;words as $key=&gt;$val)<br />
echo $key .&#8221; = &#8220;. $val.&#8221;&lt;br/&gt;&#8221;;<br />
}<br />
}<br />
?&gt;</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/72/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/72/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=72&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/06/word-counter-by-php/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>popup menu by CSS &#38; JS</title>
		<link>http://ranacse05.wordpress.com/2008/05/06/popup-menu-by-css-js/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/06/popup-menu-by-css-js/#comments</comments>
		<pubDate>Tue, 06 May 2008 18:26:16 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Web Developing]]></category>

		<category><![CDATA[css menu]]></category>

		<category><![CDATA[DHTML menu]]></category>

		<category><![CDATA[js menu]]></category>

		<category><![CDATA[popup menu]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=70</guid>
		<description><![CDATA[popup menus are very popular now a days.There are many software which helps us to create popup menus.Those software use a JavaScript file.But the main problem is its really tough to edit that JS file without that software.And one software doesn&#8217;t support another software&#8217;s files.So i was looking for some simple script which will helps [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>popup menus are very popular now a days.There are many software which helps us to create popup menus.Those software use a JavaScript file.But the main problem is its really tough to edit that JS file without that software.And one software doesn&#8217;t support another software&#8217;s files.So i was looking for some simple script which will helps me understand and what can i change when ever i want.Then i found a nice solution its based on CSS and javaScript.It is using visibility property.Here is an example.</p>
<pre>&lt;div id="MENU"
  style="<strong>position:relative</strong>; width:80px; text-align:center;
  background-color:#DC6000; color:#FFFFFF; cursor:hand"
    onmouseover="<span class="script">document.getElementById('ITEMS').style.visibility='visible'</span>"
    onmouseout="<span class="script">document.getElementById('ITEMS').style.visibility='hidden'</span>"&gt;
      Menu
&lt;/div&gt;

&lt;div id="ITEMS"
style="<strong>position:relative</strong>; <strong>visibility:hidden</strong>; width:80px; text-align:center;
background-color:#DEB887; color:#FFFFFF"
  onmouseover="<span class="script">this.style.visibility='visible'</span>"
  onmouseout="<span class="script">this.style.visibility='hidden'</span>"&gt;

  &lt;div style="background-color:#DEB887"
    onmouseover="<span class="script">this.style.backgroundColor='#9D4602'</span>"
    onmouseout="<span class="script">this.style.backgroundColor='#DEB887'</span>"
    onclick="<span class="script">location='<em>url</em>'</span>"&gt;
      Menu Item 1
  &lt;/div&gt;
  &lt;div style="background-color:#DEB887"
    onmouseover="<span class="script">this.style.backgroundColor='#9D4602'</span>"
    onmouseout="<span class="script">this.style.backgroundColor='#DEB887'</span>"
    onclick="<span class="script">location='<em>url</em>'</span>"&gt;
      Menu Item 2
  &lt;/div&gt;
  &lt;div style="background-color:#DEB887"
    onmouseover="<span class="script">this.style.backgroundColor='#9D4602'</span>"
    onmouseout="<span class="script">this.style.backgroundColor='#DEB887'</span>"
    onclick="<span class="script">location='<em>url</em>'</span>"&gt;
      Menu Item 3
  &lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;Other page content...&lt;/p&gt;</pre>
<p>Just copy and paste the code inside a HTML file and watch :).</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/70/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/70/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=70&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/06/popup-menu-by-css-js/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>SubVersion on Windows XP</title>
		<link>http://ranacse05.wordpress.com/2008/05/04/subversion-on-windows-xp/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/04/subversion-on-windows-xp/#comments</comments>
		<pubDate>Sun, 04 May 2008 18:45:12 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[Subversion]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[quick start svn]]></category>

		<category><![CDATA[subversion tutorial]]></category>

		<category><![CDATA[svn on windows xp]]></category>

		<category><![CDATA[tortoisesvn tutorial]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=69</guid>
		<description><![CDATA[Version controlling is very important now.Almost all the developers (web app/desktop) have to know it.Subversion is software which helps us in version controlling.Who dont know what is Subversion please read this.
BTW i was looking a short and nice tutorial on subversion .But i didnt got any  . Then Aman Bhai helps me to start [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Version controlling is very important now.Almost all the developers (web app/desktop) have to know it.Subversion is software which helps us in version controlling.Who dont know what is Subversion please <a href="http://en.wikipedia.org/wiki/Subversion_(software)">read this</a>.</p>
<p>BTW i was looking a short and nice tutorial on subversion .But i didnt got any <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . Then <a href="http://www.mailtoaman.com">Aman Bhai</a> helps me to start with svn . Here is the mail he sent me as a tutorial ..</p>
<p>Lets start from the beginning.</p>
<p>First you need a <strong>repository</strong>. What is it&#8230; practically its a folder on a pc that subversion (svn now on) uses as the database. This<br />
database manages version information. (skipping user/security, svn uses file system or dbms backend, default is fs).<br />
Now if you want to enable versioning with svn you must have to <strong>import </strong>that project folder into a repository.</p>
<p>After importing a project folder into a repository, you MUST <strong>checkout (</strong>download <strong>) </strong>it from that repository. It may sound weird. But think of a remote<br />
user, at least s/he has to checkout the project first right ? and you are nothing but a user to svn <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>so, lets come back to using tortoise. If you want to checkout a project from a remote site, say a google code hosted project. you just<strong> right click</strong> on the folder where you want to checkout. select <strong>tortoisesvn-&gt;import.</strong> Copy the svn url from the browser and paste to <strong>URL of repository:</strong> field. click ok, you will find the project is downloading&#8230; and done. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> now, modify any source and right click and select svn commit. Dont forget to svn update  first before any commit.</p>
<p>now,. say you are not going to use any remote project. rather you like to use svn as your local versioning. in that case you frirst create a folder that you want to use the repository. say, you created a folder named REPO. right click on the folder and select  TortoiseSVN-&gt;Create repository here&#8230; an option will appear. select Native filesystem (FSFS). done&#8230; you have created a repository successfully.</p>
<p>Now, right click on the project folder that you want to maintain versioning and select TortoiseSVN-&gt;import. click on the &#8230; button and select your repository folder i.e. REPO folder you have just created. say, it is like file://D:/REPO, now enter as file://D:/REPO/myproject.<br />
Thus you can use same repo for multiple projects.<br />
দেখবে যে তোমার প্রোজক্ট ইম্পোর্ট হয়ে গেছে under myproject folder in the REPO repository.</p>
<p>now, comes the funny part, YOU HAVE TO CHECKOUT THIS PROJECT AGAIN :).<br />
Create a folder name it &#8230;say&#8230; Workspace. Now enter into the folder.<br />
right click.<br />
TortoiseSVN-&gt;Repo browser<br />
select your REPO folder.<br />
You will find myproject folder in the tree.<br />
select it.</p>
<p>now, checkout. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Note : This is using <a href="http://tortoisesvn.tigris.org/">TortoiseSVN </a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/69/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/69/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=69&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/04/subversion-on-windows-xp/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>mod re_write Example</title>
		<link>http://ranacse05.wordpress.com/2008/05/01/mod-re_write-example/</link>
		<comments>http://ranacse05.wordpress.com/2008/05/01/mod-re_write-example/#comments</comments>
		<pubDate>Thu, 01 May 2008 20:04:48 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[Apache]]></category>

		<category><![CDATA[change the url name]]></category>

		<category><![CDATA[mod re_write]]></category>

		<category><![CDATA[mod re_write example]]></category>

		<category><![CDATA[url rewrite]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=68</guid>
		<description><![CDATA[Few days ago i was thinking how can i rewrite the url ? Then i ask phpxperts and they replay me that mod re_write can do that work.Then i  was looking for some mod re_write example.And got a nice one.Here it is I&#8217;m shearing with u all.
so, what is mod_rewrite for?
Simply, mod_rewrite is used [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Few days ago i was thinking how can i rewrite the url ? Then i ask phpxperts and they replay me that mod re_write can do that work.Then i  was looking for some mod re_write example.And got a nice one.Here it is I&#8217;m shearing with u all.</p>
<h3>so, what is mod_rewrite for?</h3>
<p>Simply, mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for <code><span style="font-size:10pt;">http://www.somesite.com/widgets/blue/</span></code>, but will really be given <code><span style="font-size:10pt;">http://www.somesite.com/widgets.php?colour=blue</span></code> by the server. Of course, the user will be none the wiser to this little bit of chicanery. .</p>
<h3>What do I need to get mod_rewrite working?</h3>
<p>There’s pretty much only one thing you’ll need to get mod_rewrite working for you, and that’s to have the mod_rewrite module installed on your Apache server!</p>
<p>For the purpose of this article, I’m going to assume that you don’t have access to view or edit the Apache server httpd.conf file, so the easiest way to check whether the mod_rewrite module is installed will be to look on your phpinfo page. If you’ve not already created one of these for yourself, just copy and paste the following code into an new text file using your favourite text editor, save it as <code><span style="font-size:10pt;">phpinfo.php</span></code>, and upload it to your server:</p>
<pre>&lt;?php phpinfo(); ?&gt;</pre>
<p>Load that page up in your web browser, and perform a search for “mod_rewrite”. All being well, you’ll find it in the “Apache loaded modules” section of the page. If it isn’t there, you’ll have to contact your hosting company and politely ask them to add it to the Apache configuration.</p>
<p>Assuming the mod_rewrite module is loaded, then you’re good to go!</p>
<h3>A simple mod_rewrite example</h3>
<p>So, let’s write a simple mod_rewrite example. This isn’t going to be anything fancy; we’re just going to redirect people who ask for <code><span style="font-size:10pt;">alice.html</span></code> to the page <code><span style="font-size:10pt;">bob.html</span></code> instead. First, let’s create the Alice and Bob pages. Below is Alice’s webpage - create a similar one for Bob.</p>
<blockquote>
<pre>&lt;html&gt;
<span>   </span>&lt;head&gt;
<span>      </span>&lt;title&gt;Alice's webpage&lt;/title&gt;
<span>   </span>&lt;/head&gt;
<span>   </span>&lt;body&gt;
<span>  </span><span>    </span>&lt;p&gt;
<span>         </span>This is Alice's webpage
<span>      </span>&lt;/p&gt;
<span>   </span>&lt;/body&gt;
&lt;/html&gt;</pre>
</blockquote>
<p>Upload both of these to your web server, and check that you can view both of them. Now comes the fun - we’re going to add a couple of lines to your .htaccess file. The .htaccess file is a text file which contains Apache directives. Any directives which you place in it will apply to the directory which the .htaccess file sits in, and any below it. To ours, we’re going to add the following:</p>
<pre>RewriteEngine on
RewriteRule ^alice.html$ bob.html</pre>
<p>Upload this .htaccess file to the same directory as alice.html and bob.html, and reload Alice’s page. You should see Bob’s page being displayed, but Alice’s URL. If you still see Alice’s page being displayed, then check you’ve followed the instructions correctly (you may have to clear your cache). If things still aren’t working for you, then contact your technical support people and ask them to enable mod_rewrite and the FileInfo override in their httpd.conf file for you</p>
<h3>The structure of a RewriteRule</h3>
<pre>RewriteRule <em>Pattern Substitution [OptionalFlags]</em></pre>
<p>The general structure of a RewriteRule is fairly simple if you already understand regular expressions. This article isn’t intended to be a tutorial about regular expressions though - there are already plenty of those available. RewriteRules are broken up as follows:</p>
<p class="MsoNormal">RewriteRule</p>
<p style="margin-left:0.5in;">This is just the name of the command.</p>
<p class="MsoNormal">Pattern</p>
<p style="margin-left:0.5in;">A regular expression which will be applied to the “current” URL. If any RewriteRules have already been performed on the requested URL, then that changed URL will be the current URL.</p>
<p class="MsoNormal">Substitution</p>
<p style="margin-left:0.5in;">Substitution occurs in the same way as it does in Perl, PHP, etc.</p>
<p style="margin-left:0.5in;">You can include backreferences and server variable names (<code><span style="font-size:10pt;">%{VARNAME}</span></code>) in the substitution. Backreferences to this RewriteRule should be written as <code><span style="font-size:10pt;">$N</span></code>, whereas backreferences to the previous RewriteCond should be written as <code><span style="font-size:10pt;">%N</span></code>.</p>
<p style="margin-left:0.5in;">A special substitution is <code><span style="font-size:10pt;">-</span></code>. This substitution tells Apache to not perform any substitution. I personally find that this is useful when using the <code><span style="font-size:10pt;">F</span></code> or <code><span style="font-size:10pt;">G</span></code> flags (see below), but there are other uses as well.</p>
<p class="MsoNormal">OptionalFlags</p>
<p style="margin-left:0.5in;">This is the only part of the RewriteRule which isn’t mandatory. Any flags which you use should be surrounded in square brackets, and comma separated. The flags which I find to be most useful are:</p>
<p style="margin-left:1in;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span dir="ltr"><code><span style="font-size:10pt;">F</span></code> - Forbidden. The user will receive a 403 error. </span></p>
<p style="margin-left:1in;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span dir="ltr"><code><span style="font-size:10pt;">L</span></code> - Last Rule. No more rules will be proccessed if this one was successful. </span></p>
<p style="margin-left:1in;text-indent:-0.25in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font-family:&quot;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span dir="ltr"><code><span style="font-size:10pt;">R[=code]</span></code> - Redirect. The user’s web browser will be visibly redirected to the substituted URL. If you use this flag, you <em>must</em> prefix the substitution with </span><code><span style="font-size:10pt;">http://www.somesite.com/</span></code>, thus making it into a true URL. If no code is given, then a HTTP reponse of 302 (temporarily moved) is sent.</p>
<p style="margin-left:0.5in;">A full list of flags is given in the Apache mod_rewrite manual.</p>
<h3>A slightly more complicated mod_rewrite example</h3>
<p>Let’s try a slightly more meaty example now. Suppose you have a web page which takes a parameter. This parameter tells the page how to be displayed, and what content to pull into it. Humans don’t tend to like remembering the additional syntax of query strings for URLs, and neither do search engines. Both sets of people seem to much prefer a straight URL, with no extra bits tacked onto the end.</p>
<p>In our example, you’ve created a main index page with takes a <code><span style="font-size:10pt;">page</span></code> parameter. So, a link like <code><span style="font-size:10pt;">index.php?page=software</span></code> would take you to a software page, while a link to <code><span style="font-size:10pt;">index.php?page=interests</span></code> would take you to an interests page. What we’ll do with mod_rewrite is to silently redirect users from <code><span style="font-size:10pt;">page/software/</span></code> to <code><span style="font-size:10pt;">index.php?page=software</span></code> etc.</p>
<p>The following is what needs to go into your .htaccess file to accomplish that:</p>
<pre>RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]</pre>
<p>Let’s walk through that RewriteRule, and work out exactly what’s going on:</p>
<p class="MsoNormal">^page/</p>
<p style="margin-left:0.5in;">Sees whether the requested page starts with <code><span style="font-size:10pt;">page/</span></code>. If it doesn’t, this rule will be ignored.</p>
<p class="MsoNormal">([^/.]+)</p>
<p style="margin-left:0.5in;">Here, the enclosing brackets signify that anything that is matched will be remembered by the RewriteRule. Inside the brackets, it says “I’d like one or more characters that aren’t a forward slash or a period, please”. Whatever is found here will be captured and remembered.</p>
<p class="MsoNormal">/?$</p>
<p style="margin-left:0.5in;">Makes sure that the only thing that is found after what was just matched is a possible forward slash, and nothing else. If anything else is found, then this RewriteRule will be ignored.</p>
<p class="MsoNormal">index.php?page=$1</p>
<p style="margin-left:0.5in;">The actual page which will be loaded by Apache. <code><span style="font-size:10pt;">$1</span></code> is magically replaced with the text which was captured previously.</p>
<p class="MsoNormal">[L]</p>
<p style="margin-left:0.5in;">Tells Apache to not process any more RewriteRules if this one was successful.</p>
<p>Let’s write a quick page to test that this is working. The following test script will simply echo the name of the page you asked for to the screen, so that you can check that the RewriteRule is working.</p>
<blockquote>
<pre>&lt;html&gt;
<span>   </span>&lt;head&gt;
<span>      </span>&lt;title&gt;Second mod_rewrite example&lt;/title&gt;
<span>   </span>&lt;/head&gt;
<span>   </span>&lt;body&gt;
<span>      </span>&lt;p&gt;
<span>         </span>The requested page was:
<span>         </span>&lt;?php echo $_GET['page']; ?&gt;
<span>      </span>&lt;/p&gt;
<span>   </span>&lt;/body&gt;</pre>
<p>RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?somesite.com/.*$ [NC]RewriteRule \.(gif|jpg|png)$ http://www.somesite.com/nasty.gif [R,L]</p></blockquote>
<pre>&lt;/html&gt;
</pre>
<p>Again, upload both the index.php page, and the .htaccess file to the same directory. Then, test it! If you put the page in <code><span style="font-size:10pt;">http://www.somesite.com/mime_test/</span></code>, then try requesting <code><span style="font-size:10pt;">http://www.somesite.com/mime_test/page/software</span></code>. The URL in your browser window will show the name of the page which you requested, but the content of the page will be created by the <code><span style="font-size:10pt;">index.php</span></code> script! This technique can obviously be extended to pass multiple query strings to a page - all you’re limited by is your imagination.</p>
<h3>Conditional Statements and mod_rewrite</h3>
<p>But what happens when you start getting people hotlinking to your images (or other files)? Hot linking is the act of including an image, media file, etc from someone else’s server in one of your own pages as if it were your own. Obviously, as a webmaster, there are plenty of times when you don’t want people doing that. You’ll almost certainly have seen examples where someone has linked to one image on a website, only for a completely different, “nasty” one to be shown instead. So, how is this done?</p>
<p>It’s pretty simple really. All it takes are a couple of RewriteCond statements in your .htaccess file.</p>
<p>RewriteCond statements are as they sound - conditional statements for RewriteRules. The basic format for a RewriteCond is <code><span style="font-size:10pt;">RewriteCond test_string cond_pattern</span></code>. For our purpose, we will set the test_string to be the HTTP_REFERER. If the test string is neither empty nor our own server, then we will serve an alternative (low bandwidth) image, which tells the person who is hotlinking off for stealing our bandwidth.</p>
<p>Here’s how we do that:</p>
<p>Here, the RewriteRule will only be performed if all the preceeding RewriteConds are fulfilled. In the second RewriteCond, <code><span style="font-size:10pt;">[NC]</span></code> simply means “No Case”, so it doesn’t matter whether the domain name was written in upper case, lower case or a mixture of the two. So, any requests for gif, jpg or png files from referers other than somesite.com will result in your “nasty” image being shown instead.</p>
<p>The <code><span style="font-size:10pt;">[R,L]</span></code> in the RewriteRule simply means “Redirect, Last”. So, the RewriteRule will visibly redirect output to “nasty.gif” and no more RewriteRules will be performed on this URL.</p>
<p>If you simply don’t want the hot linkers to see any image at all when they hot link to your images, then simply change the final line to <code><span style="font-size:10pt;">RewriteRule \.(gif|jpg|png)$ - [F]</span></code>. The <code><span style="font-size:10pt;">-</span></code> means “don’t rewrite the requested URL”, and the <code><span style="font-size:10pt;">[F]</span></code> means “Forbidden”. So, the hot linker will get a “403 Forbidden message”, and you don’t end up wasting your bandwidth.</p>
<p>Note : This is the <a href="http://www.workingwith.me.uk/articles/scripting/mod_rewrite">original link</a> .</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/68/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/68/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=68&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/05/01/mod-re_write-example/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
		<item>
		<title>Header Tutorial</title>
		<link>http://ranacse05.wordpress.com/2008/04/28/header-tutorial/</link>
		<comments>http://ranacse05.wordpress.com/2008/04/28/header-tutorial/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 02:54:57 +0000</pubDate>
		<dc:creator>ranacse05</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[Web Developing]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[header()]]></category>

		<guid isPermaLink="false">http://ranacse05.wordpress.com/?p=67</guid>
		<description><![CDATA[I was looking for a nice tutorial on header() in php . The www.php.net/header is not enough.Actually if i have to learn any thing of php first i search it in www.php.net if i fail then some yahoo groups.But this time i cant get enough idea about header() then i google it and got nice [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was looking for a nice tutorial on <span style="color:#008000;">header() <span style="color:#000000;">in php . The <a href="http://www.php.net/header">www.php.net/header</a> is not enough.Actually if i have to learn any thing of php first i search it in www.php.net if i fail then some yahoo groups.But this time i cant get enough idea about <span style="color:#008000;">header()</span> then i google it and got nice tuto on <span style="color:#008000;">header()</span>.<a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html">Here is the link</a> .And the tutorial is here</span></span></p>
<h1 style="margin:0.25in;"><span style="color:#008000;">HTTP Headers and the PHP header() Function</span></h1>
<p class="MsoNormal">
<p><strong>A tutorial by NicholasSolutions</strong></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>1.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#intro">Introduction</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>2.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#http_overview">Overview of HTTP Headers</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>3.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#phpheaders">PHP <code><span style="font-size:10pt;">header()</span></code>: The Basics</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>4.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#phpheaderex">PHP <code><span style="font-size:10pt;">header()</span></code>: Some Examples</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>5.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#requestheaders">Request Headers in PHP</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>6.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#metaequiv">HTML Meta Tag HTTP Header Equivalents</a></span></p>
<p class="MsoNormal" style="margin-left:12pt;text-indent:-0.25in;"><!--[if !supportLists]--><span>7.<span> </span></span><!--[endif]--><span dir="ltr"><a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#conclusion">Conclusion</a></span></p>
<h2><a id="intro" name="intro"></a>Introduction</h2>
<p>Many beginning and intermediate PHP programmers seem to think the <code><span style="font-size:10pt;"><a href="http://www.php.net/manual/function.header.php">header()</a></span></code> function is some kind of strange voodoo. They work from examples and code snippets and are able to get things done with it, but they don&#8217;t know quite how it works. That was certainly the way I regarded <code><span style="font-size:10pt;">header()</span></code> the first time I saw it.</p>
<p>In reality, it&#8217;s quite simple. In this tutorial, I&#8217;ll explain a little about how HTTP headers work, how they relate to PHP, and a little about their meta tag equivalents.</p>
<p>Hopefully by the time you&#8217;re done reading this, you&#8217;ll feel more confident about how to use the <code><span style="font-size:10pt;">header()</span></code> function, and even have some new ideas about how it can help you. We&#8217;ll also cover some other important topics related to HTTP headers and PHP. Before we talk about any programming at all, though, we need to quickly (and incompletely) go over how HTTP (<strong>H</strong>yper<strong>T</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol) works in general.</p>
<h2><a id="http_overview" name="http_overview"></a>HTTP Overview</h2>
<h3>Headers: words in a conversation</h3>
<p><a href="http://en.wikipedia.org/wiki/HyperText_Transfer_Protocol">HTTP</a> is the protocol (the set of &#8216;rules&#8217;) for transferring data (e.g. HTML in web pages, pictures, files) between web servers and client browsers, and usually takes place on <a href="http://en.wikipedia.org/wiki/Port_%28computing%29#Network_port">port</a> 80. This is where the &#8216;<code><span style="font-size:10pt;">http://</span></code>&#8216; in website URLs comes from.</p>
<p>The first time most people make a web page, they write the HTML on their computer, view it locally in a browser, upload it to their server, and view it on the web. It might seem like viewing a page locally and viewing it on the server is exactly the same, and that the only data going back and forth between the server and the browser is the HTML and any images included in the page. But there is actually a lot of other information that you do not see when you view a file on the web — the <em>headers</em>.</p>
<p>Headers can be separated into two broad types: <em>Request</em> headers that your browser sends to the server when you request a file, and <em>Response</em> headers that the server sends to the browser when it serves the file. Think of these headers as the words in a conversation taking place between the browser and the server. I like to imagine the server as a librarian, and the browser as a researcher asking for a library resource. The browser walks up to the server at the main desk (port 80) and says something like, &#8220;Hi, my name is Mozilla, and I&#8217;m looking for the resource with the call number &#8216;www.expertsrt.com&#8217;. Can you get it for me?&#8221; The server listens, and responds &#8220;Yes, I found it, let me send it to you. The data in the item is HTML text, and it says &#8216;<code><span style="font-size:10pt;">&lt;html&gt;</span></code>&#8230;&#8217;&#8221; The browser reads through, and comes to an image tag, and asks the server for item with the location in the <code><span style="font-size:10pt;">src</span></code> attribute. The server looks, finds the file and says &#8220;This file is a PNG image, and the data is&#8230;.&#8221; You get the idea.</p>
<p>Another conversation might go like this:</p>
<p><em>Browser:</em> Hi, I&#8217;m Mozilla, can I have the file at &#8216;www.expertsrt.com/moved.html&#8217;?<br />
<em>Server:</em> That file is no longer there, it is at &#8216;www.expertsrt.com/newloc.html&#8217;.<br />
<em>Browser:</em> Hi, I&#8217;m Mozilla, can I have the file at &#8216;www.expertsrt.com/newloc.html&#8217;?<br />
<em>Server:</em> I found the file. Look at it for 10 seconds and then ask me again. It&#8217;s HTML text and it reads&#8230;.<br />
&#8230;10 seconds&#8230;<br />
<em>Browser:</em>&gt; Hi, I&#8217;m Mozilla, can I have the file at &#8216;www.expertsrt.com/newloc.html&#8217;?<br />
<em>Server:</em> I found the file. Look at it for 10 seconds and then ask me again. It&#8217;s HTML text and it reads&#8230;.<br />
&#8230;10 seconds&#8230;<br />
<em>Browser:</em> Hi, I&#8217;m Mozilla, can I have the file at &#8216;www.expertsrt.com/newloc.html&#8217;?<br />
<em>Server:</em> I found the file. Look at it for 10 seconds and then ask me again. It&#8217;s HTML text and it reads&#8230;.<br />
&#8230;.and so on, until the browser is redirected by the user&#8230;.</p>
<p>As you can see, there is a lot going on that headers control. Using the <code><span style="font-size:10pt;">header()</span></code> function, you can make the server send any headers that you need want, which allows you to do some really cool things beyond just sending plain old HTML.</p>
<h3>Seeing the whole conversation</h3>
<p>Before moving ahead, let&#8217;s get a better idea of how HTTP headers work by viewing a webpage <em>without</em> a browser, so we can see the converation in is entirety. Start by opening a command prompt (in windows, go to Start-&gt;Run, type <code><span style="font-size:10pt;">cmd</span></code>, and click &#8220;OK&#8221;&#8230;if you&#8217;re using linux you probably already know). At the prompt, type:</p>
<pre><code>telnet expertsrt.com 80</code></pre>
<p>and press Enter. This will connect you to expertsrt.com on port 80. Next, copy and paste just the text below:</p>
<pre><code>GET / HTTP/1.1</code>
<code>Host: expertsrt.com</code></pre>
<p>Don&#8217;t worry if when you type or paste the text, it does not show up in your command window and all you see is the cursor &#8212; it is indeed being sent to the server. The first line says you are using the <code><span style="font-size:10pt;">GET</span></code> request method to get the resource <code><span style="font-size:10pt;">/</span></code> (i.e. the file in the base directory of the host), and that you are using HTTP version 1.1. The second tells the server which host you want to connect to. When you finish typing &#8216;expertsrt.com&#8217;, hit Enter twice (and twice only). You should almost immediately get a response that looks like:</p>
<pre><code>HTTP/1.1 301 Moved Permanently</code>
<code>Date: </code><code>Wed, 08 Feb 2006</code><code> </code><code>07:44:07 GMT</code>
<code>Server: Apache/2.0.54 (Debian GNU/Linux) mod_auth_pgsql/2.0.2b1 mod_ssl/2.0.54 OpenSSL/0.9.7e</code>
<code>Location: http://www.expertsrt.com/</code>
<code>Content-Length: 233</code>
<code>Content-Type: text/html; charset=iso-8859-1</code>
<code> </code>
<code>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;</code>
<code>&lt;html&gt;&lt;head&gt;</code>
<code>&lt;title&gt;301 Moved Permanently&lt;/title&gt;</code>
<code>&lt;/head&gt;&lt;body&gt;</code>
<code>&lt;h1&gt;Moved Permanently&lt;/h1&gt;</code>
<code>&lt;p&gt;The document has moved &lt;a href="http://www.expertsrt.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;</code>
<code>&lt;/body&gt;&lt;/html&gt;</code></pre>
<p>Whoops! Looks like we requested a resource that wasn&#8217;t there; it&#8217;s been permanently moved to the new Location <code><span style="font-size:10pt;">http://www.expertsrt.com</span></code>. If you were using a browser, you&#8217;d only see the HTML — everything before the first blank line is the headers. In fact, modern browsers are even smarter than that — when they see the <code><span style="font-size:10pt;">Location</span></code> header on the third line, they automatically go there so you don&#8217;t have to type in a new URL. Let&#8217;s go to the new URL. By this point, you probably got disconnected while you were reading this. If so, just press your up arrow on the keyboard to get your <code><span style="font-size:10pt;">telnet</span></code> command back, and press enter to reconnect. If you&#8217;re still connected, you can just go ahead and type the following:</p>
<pre><code>GET / HTTP/1.1</code>
<code>Host: www.expertsrt.com</code></pre>
<p>and press Enter twice after the second line. You&#8217;ll get another similar response telling you that the page is <em>actually</em> at <code><span style="font-size:10pt;">http://www.expertsrt.com/index.php</span></code>. The server is particular, isn&#8217;t it? <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> Repeat the above, but this time type</p>
<pre><code>GET /index.php HTTP/1.1</code>
<code>Host: www.expertsrt.com</code></pre>
<p>Notice that the name of the file we want is in the first line. This time we get flooded with text: the HTML from ERT&#8217;s homepage. The headers look like</p>
<pre><code>HTTP/1.1 200 OK</code>
<code>Date: </code><code>Wed, 08 Feb 2006</code><code> </code><code>08:20:07 GMT</code>
<code>Server: Apache/2.0.54 (Debian GNU/Linux) mod_auth_pgsql/2.0.2b1 mod_ssl/2.0.54 OpenSSL/0.9.7e</code>
<code>X-Powered-By: PHP/4.4.0</code>
<code>Transfer-Encoding: chunked</code>
<code>Content-Type: text/html</code></pre>
<p>Simple, no?. Let&#8217;s move forward and see how this relates to your programming. Don&#8217;t worry if you didn&#8217;t understand every single thing that we just did. The important thing is to have a general feel for how the browser and server talk to each other, and to realize that <em>there is nothing magic about it.</em> The take home points are:</p>
<ul type="disc">
<li class="MsoNormal">The browser and the server      talk to each other using headers</li>
<li class="MsoNormal">Headers are sent before the      main content, and are separated from the main content by a a double-<a href="http://www.google.com/search?q=define%3ACRLF">CRLF</a>/newline.</li>
<li class="MsoNormal">In the header section, there      is one header per line. The name of the header comes first, followed by a      colon and a space, followed by the content/value of the header:</li>
</ul>
<p class="MsoNormal" style="margin-left:0.5in;"><code><span style="font-size:10pt;">Header-Name: header-value</span></code></p>
<ul type="disc">
<li class="MsoNormal">Headers can contain many      types of information and instructions that the server and browser use to      help each other know what to do next</li>
</ul>
<p><strong>Note</strong>: If you&#8217;re the type who likes to really dig into the details, you can look at <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">RFC 2616</a> for the complete HTTP/1.1 specification in all its glory. In particular, <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14">Section 14</a> offers a complete definition for each header field.</p>
<p class="MsoNormal">
<p class="MsoNormal">
<h2>PHP <code><span style="font-size:10pt;">header()</span></code>: The Basics</h2>
<p>Notice the response headers <code><span style="font-size:10pt;">X-Powered-By: PHP/4.4.0</span></code> and <code><span style="font-size:10pt;">Content-Type: text/html</span></code> that were returned when we finally got to the homepage. PHP was designed from the beginning to output HTML (the &#8216;H&#8217; in PHP stands for &#8216;Hypertext&#8217;), and the first time a script generates output (e.g. by using <code><span style="font-size:10pt;">echo</span></code>), PHP automatically includes those headers for you. This is very convenient, but also contributes to the confusion many PHP beginners have regarding headers — in more &#8216;bare bones&#8217; languages like Perl that were not originally designed for the web, sending output without including your own headers produces the dreaded &#8216;500 Internal Server Error&#8217;, so Perl web programmers have no choice but to learn about headers immediately.</p>
<p>The <code><span style="font-size:10pt;"><a href="http://www.php.net/manual/function.header.php">header()</a></span></code> function sends HTTP response headers; nothing more, nothing less.</p>
<div class="MsoNormal" style="text-align:center;">
<hr size="2" /></div>
<p>Using this function, you can make your scripts send headers of your choosing to the browser, and create some very useful and dynamic results. However, the first thing you need to know about the <code><span style="font-size:10pt;">header()</span></code> function is that you have to use it <strong>before</strong> PHP has sent any output (and therefore its default headers).</p>
<p>I doubt there is a PHP programmer in the world who has never seen an error that looks like</p>
<p class="MsoNormal"><strong>Warning:</strong> Cannot modify header information - headers already sent by&#8230;..</p>
<p>As we said above, the response headers are separated from the content by a blank line. This means you can only send them <em>once</em>, and if your script has any output (even a blank line or space before your opening <code><span style="font-size:10pt;color:#0000bb;">&lt;?php</span></code> tag), PHP does so without asking you. For example, consider the script below, which seems logical enough:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:black;">Welcome to my website!&lt;br /&gt; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">if(</span></code><code><span style="font-size:10pt;color:#0000bb;">$test</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8220;You&#8217;re in!&#8221;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
<code> else{ </code><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/someotherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>What this script is <em>trying</em> to do is redirect the visitor using the <code><span style="font-size:10pt;">Location</span></code> header if <code><span style="font-size:10pt;">$test</span></code> is not true. Do you see the problem? The &#8216;Welcome&#8230;&#8217; text gets sent no matter what, so the headers are automatically sent. By the time <code><span style="font-size:10pt;">header()</span></code> is called, it&#8217;s already too late: instead of getting redirected, the user will just see an error message (or if you have error reporting off, nothing but the &#8216;Welcome&#8230;&#8217; text).</p>
<p>There are basically two solutions to this. The first is to rewrite the code</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">if(</span></code><code><span style="font-size:10pt;color:#0000bb;">$test</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;Welcome to my website&lt;br /&gt;You&#8217;re in!&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
<code> else{ </code><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/someotherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>The second is <a href="http://www.php.net/outcontrol">output buffering</a>, which can be somewhat more elegant and easy to use. In our example above, rewriting the code wasn&#8217;t much trouble, but imagine if there had been quite a bit of HTML to move around — it could be pretty cumbersome, and it might make our code harder to follow. While our first example caused an error, the <em>logic of the program</em> was fine. Output buffering allows you to hold on to (&#8217;buffer&#8217;) output (even HTML outside of PHP code tags) and send it to the browser only when you explicitly say to do so. This way you can program however you would like to, and explicitly send the output after you&#8217;ve specified any headers you need to. The two relevant functiosns are <code><span style="font-size:10pt;"><a href="http://www.php.net/manual/function.ob-start.php">ob_start()</a></span></code>, which turns output buffering on, and <code><span style="font-size:10pt;"><a href="http://www.php.net/manual/function.ob-flush.php">ob_flush()</a></span></code>, which sends the content that has accumulated in the buffer:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> ob_start</code></span><code><span style="font-size:10pt;color:#007700;">(); </span></code><code><span style="font-size:10pt;color:#666666;">//begin buffering the output </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:black;">Welcome to my website! </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">if(</span></code><code><span style="font-size:10pt;color:#0000bb;">true</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8220;You&#8217;re in!&#8221;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
<code> else{ </code><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/someotherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> } </code></span></p>
<p><code> </code><code><span style="font-size:10pt;color:#0000bb;">ob_flush</span></code><code><span style="font-size:10pt;color:#007700;">(); </span></code><code><span style="font-size:10pt;color:#666666;">//output the data in the buffer </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>I encourage you to read more about all of the output buffering functions, which can be quite useful. You should flush the output buffer as soon as possible, especially if you have quite a bit of content to send. Otherwise, your page will appear to load slower, becuase the content will be sent only after it has been entirely assembled, rather than as it is available.</p>
<p><strong>Note: The 2nd argument</strong> If you call <code><span style="font-size:10pt;">header()</span></code> more than once for the same header field, the value for that header will be the one included in the <em>last</em> call you made. For example,</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Some-Header: Value-1&#8242;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Some-Header: Value-2&#8242;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>would produce the header <code><span style="font-size:10pt;">Some-Header: Value-2</span></code>. You can cause both headers to be sent by using the second <code><em><span style="font-size:10pt;">replace</span></em></code> argument for header, which is <code><span style="font-size:10pt;">true</span></code> by default. If you set this to <code><span style="font-size:10pt;">false</span></code>, the second header value will not replace the first, and both will be sent. So the code</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Some-Header: Value-1&#8242;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Some-Header: Value-2&#8242;</span></code><code><span style="font-size:10pt;color:#007700;">, </span></code><code><span style="font-size:10pt;color:#0000bb;">false</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><code><span style="font-size:10pt;color:#666666;">//don&#8217;t replace the first value </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code><code><span style="font-size:10pt;"> </span></code></p>
<p>will produce the header <code><span style="font-size:10pt;">Some-Header: Value-1, Value-2</span></code>. You will rarely need this, but is good to know.</p>
<p>Armed with a good understanding of how HTTP headers and PHP work together, let&#8217;s look at some specific examples of using this functionality.</p>
<h2>PHP <code><span style="font-size:10pt;">header()</span></code>: Some Examples</h2>
<p><strong>Note:</strong> The code snippets appearing below are just that: snippets from complete working code. When you you include them in your own programs, remember to define all your variables, assign default values, and adhere to other good programming practices.</p>
<h3>Redirecting with the <code><span style="font-size:10pt;">Location</span></code> header</h3>
<p>We&#8217;ve seen this one a couple times above: it redirects the browser.</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/new_location.html&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>While you can somtimes get away with supplying a relative URL for the value, according to the HTTP specification, you should really use an absolute URL.</p>
<p>One mistake that is easy to make with the <code><span style="font-size:10pt;">Location</span></code> header is not calling <code><span style="font-size:10pt;"><a href="http://www.php.net/manual/function.exit.php"><span style="font-size:12pt;">exit</span></a></span></code> directly afterwards (you may not always want to do this, but usually you do). The reason this is a mistake is that the PHP code of the page continues to execute even though the user has gone to a new location. In the best case, this uses system resources unnecessarily. In the worst case, you may perform tasks that you never meant to. Consider the code below:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#666666;">//Redirect users with access level below 4 </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#007700;">if (</span></code><code><span style="font-size:10pt;color:#0000bb;">check_access_level</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$username</span></code><code><span style="font-size:10pt;color:#007700;">) &lt; </span></code><code><span style="font-size:10pt;color:#0000bb;">4</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/someotherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>} </code></span></p>
<p><code><span style="font-size:10pt;color:#666666;">//Mail users with higher access level the secret code </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">mail_secret_code</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$username</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;The secret email is on its way!&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>Unauthorized users are indeed redirected, but in fact, they too will receive the email, because the script continues to run. To avoid this, the part for authorized users could be wrapped in an <code><span style="font-size:10pt;">else{}</span></code> statement, but it is cleaner and easier to call <code><span style="font-size:10pt;">exit</span></code> immediately after the <code><span style="font-size:10pt;">header</span></code> command to end the execution of the script:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#666666;">//Redirect users with access level below 4 </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#007700;">if (</span></code><code><span style="font-size:10pt;color:#0000bb;">check_access_level</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$username</span></code><code><span style="font-size:10pt;color:#007700;">) &lt; </span></code><code><span style="font-size:10pt;color:#0000bb;">4</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Location: http://www.mysite.com/someotherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> exit; </code></span><code><span style="font-size:10pt;color:#666666;">//stop script execution </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#007700;">} </span></code></p>
<p><code><span style="font-size:10pt;color:#666666;">//Mail users with higher access level the secret code </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">mail_secret_code</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$username</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;The secret email is on its way!&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<h3>Redirecting with the <code><span style="font-size:10pt;">Refresh</span></code> header</h3>
<p>The <code><span style="font-size:10pt;">Refresh</span></code> redirects users like the <code><span style="font-size:10pt;">Location</span></code> header does, but you can add a delay before the user is redirected. For example, the following code would redirect the user to a new page after displaying the current one for 10 seconds:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Refresh: 10; url=http://www.mysite.com/otherpage.php&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;You will be redirected in 10 seconds&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>Another common application is to force a page to update repeatedly by &#8216;redirecting&#8217; to the current page (see the second &#8216;conversation&#8217; <a href="http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html#secondconv">above</a>). For example, here is a simple page that will &#8216;count&#8217; down from 10, with a 3 second pause between numbers:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#007700;">if(!isset(</span></code><code><span style="font-size:10pt;color:#0000bb;">$_GET</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'n'</span></code><code><span style="font-size:10pt;color:#007700;">])){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">$_GET</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'n'</span></code><code><span style="font-size:10pt;color:#007700;">] = </span></code><code><span style="font-size:10pt;color:#0000bb;">10</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code>} </code></span></p>
<p><code>if(</code><code><span style="font-size:10pt;color:#0000bb;">$_GET</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'n'</span></code><code><span style="font-size:10pt;color:#007700;">] &gt; </span></code><code><span style="font-size:10pt;color:#0000bb;">0</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Refresh: 3; url=&#8217; </span></code><code><span style="font-size:10pt;color:#007700;">. </span></code><code><span style="font-size:10pt;color:#0000bb;">$_SERVER</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'PHP_SELF'</span></code><code><span style="font-size:10pt;color:#007700;">].</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;?n=&#8217; </span></code><code><span style="font-size:10pt;color:#007700;">. (</span></code><code><span style="font-size:10pt;color:#0000bb;">$_GET</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'n'</span></code><code><span style="font-size:10pt;color:#007700;">]-</span></code><code><span style="font-size:10pt;color:#0000bb;">1</span></code><code><span style="font-size:10pt;color:#007700;">)  ); </span></code><span style="font-size:10pt;"><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#0000bb;">$_GET</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'n'</span></code><code><span style="font-size:10pt;color:#007700;">]; </span></code><span style="font-size:10pt;"><br />
<code>} </code><br />
<code>else{ </code><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;BLAST OFF!&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code>} </code><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p class="MsoNormal"><strong>Note:</strong> If the refresh time is set to 0, then the <code><span style="font-size:10pt;">Refresh</span></code> header is effectively the same as the <code><span style="font-size:10pt;">Location</span></code> header.</p>
<h3>Serving different types of files and generating dynamic content using the <code><span style="font-size:10pt;">Content-Type</span></code> header</h3>
<p>The <code><span style="font-size:10pt;">Content-Type</span></code> header tells the browser what type of data the server is about to send. Using this header, you can have your PHP scripts output anything from plain text files to images or zip files. The table below lists frequently-used <a href="http://en.wikipedia.org/wiki/Mime_type">MIME types</a>:</p>
<p>You can do several interesting things with this. For example, perhaps you want to send the user a pre-formatted text file rather than HTML:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Type: text/plain&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>echo </code></span><code><span style="font-size:10pt;color:#0000bb;">$plain_text_content</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>Or perhaps you&#8217;d like to prompt the user to download the file, rather than viewing it in the browser. With the help of the <code><span style="font-size:10pt;">Content-Disposition</span></code> header, it&#8217;s easy to do, and you can even suggest a file name for the user to use:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Type: application/octet-stream&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Disposition: attachment; &#8216; </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">.</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;filename=&#8221;plain_text_file.txt&#8221;&#8216;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>echo </code></span><code><span style="font-size:10pt;color:#0000bb;">$plain_text_content</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>Maybe you need to serve a file for download, but you&#8217;d like to obscure its true location and name, and only serve it to users who are logged in:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#007700;">if(</span></code><code><span style="font-size:10pt;color:#0000bb;">$b_is_logged_in</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Type: application/octet-stream&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Disposition: attachment; &#8216; </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">.</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;filename=&#8221;&#8216;</span></code><code><span style="font-size:10pt;color:#007700;">.</span></code><code><span style="font-size:10pt;color:#0000bb;">$different_filename</span></code><code><span style="font-size:10pt;color:#007700;">.</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;&#8221;&#8216;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">readfile</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;/path/to/files/&#8217; </span></code><code><span style="font-size:10pt;color:#007700;">. </span></code><code><span style="font-size:10pt;color:#0000bb;">$filename</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code>} </code><br />
<code>else{ </code><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;You are not authorized to view this file&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code>} </code><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p>Perhaps you&#8217;ve dynamically generated an image using PHP&#8217;s <a href="http://www.php.net/manual/ref.image.php">image functions</a> and you want to display it to the user. You could create a file <code><span style="font-size:10pt;">build_image.php</span></code> like this</p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding:0.75pt;" colspan="2">
<p class="MsoNormal" style="margin-bottom:24pt;text-align:center;" align="center">Common   MIME types</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;text-align:center;" align="center"><strong>Type</strong></p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;text-align:center;" align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">text/html</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">HTML (PHP default)</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">text/plain</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Plain Text</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">image/gif</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">GIF Image</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">image/jpeg</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">JPEG Image</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">image/png</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">PNG Image</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">video/mpeg</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">MPEG Video</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">audio/wav</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">WAV Audio</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">audio/mpeg</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">MP3 Audio</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">video/mov<br />
video/quicktime</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Quicktime Video</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">video/x-ms-wmv</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Windows WMV video</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">audio/x-ms-wma</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Windows WMA audio</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">audio/x-realaudio</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">RealPlayer Audio/Video (.rm)</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">audio/x-pn-realaudio</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">RealPlayer Audio/Video (.ram)</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">video/x-msvideo<br />
video/avi</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">AVI Video</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">application/pdf</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">PDF Document</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">application/msword</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">MS Word .doc file</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">application/zip</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Zip File</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">application/octet-stream</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Misc. data. Use to force   download or open with application.*</p>
</td>
</tr>
<tr>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">x-foo/x-bar</p>
</td>
<td style="padding:0.75pt;">
<p class="MsoNormal" style="margin-bottom:24pt;">Misc. data. Use to force   download or open with application.*</p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#666666;">//build the image above </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Content-Type: image/jpeg&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">imagejpeg</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$image_resouce</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code></p>
<p><strong>Note</strong>: Beware of <a href="http://www.php.net/magic_quotes">magic_quotes</a>! PHP&#8217;s automatic escaping of special characters with a backslash may seem like a good idea at first, but most good programmers generally agree that it (a) encourages sloppy programming that does not validate input and (b) causes annoyances in well-written code that would not occur if &#8220;magic quoting&#8221; were turned off. One such annoyance is the corruption of binary data. In the example above, if <a href="http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime"><code><span style="font-size:10pt;">magic_quotes_runtime</span></code></a> is on, the data that <code><span style="font-size:10pt;">readfile()</span></code> outputs may have backslashes added to it, thus corrupting the file that is sent to the user. Ideally, you should turn <code><span style="font-size:10pt;">magic_quotes_runtime</span></code> off in your <code><span style="font-size:10pt;">php.ini</span></code> file to avoid this, but if you do not have access to the configuration file, you can also use the <a href="http://www.php.net/manual/en/function.set-magic-quotes-runtime.php">set_magic_quotes_runtime()</a> function (pass is the <code><span style="font-size:10pt;">0</span></code> (zero) integer) to turn the setting off.</p>
<p>Happily, the <a href="http://www.php.net/%7Ederick/meeting-notes.html#magic-quotes">minutes</a> of a recent PHP Developer meeting show that they have decided to abandon magic quotes in future versions (6+) of PHP. Until everyone upgrades, however, keeping the problems this feature can cause in mind can save you quite a bit of trouble and frustration.<br />
You might pass the parameters necessary to generate the image via the URL so you can access them in the <code><span style="font-size:10pt;">$_GET</span></code> array. Then in another page, you might include this image using an <code><span style="font-size:10pt;">img</span></code> tag:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:black;">&lt;img src=&#8221;build_image.php</span></code><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><code><span style="font-size:10pt;color:#007700;">echo </span></code><code><span style="font-size:10pt;color:#dd0000;">&#8220;?$user_id&amp;$caption&#8221;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;">&#8220;&gt;</span></code><code><span style="font-size:10pt;"> </span></code></p>
<p>The possibilities are more or less endless. The more PHP programming you do, the more you will find that the <code><span style="font-size:10pt;">Content-Type</span></code> header truly is your friend.</p>
<p><strong>Note</strong>: The way that browser are <em>supposed</em> to handle content of various MIME types, and the way they actually <em>do</em> may not always be consistent (especially with Internet Explorer), so you&#8217;re well-advised to test your pages in the browsers you need to support to make sure they behave as expected. The PHP Manual has many helpful tips in the <a href="http://www.php.net/manual/function.header.php#usernotes">user-contributed comments</a> on the <code><span style="font-size:10pt;">header()</span></code> page.</p>
<h3>Preventing Page Caching</h3>
<p>PHP pages often generate very dynamic content, and to prevent users from missing updates by viewing cached pages, it is often helpful to be able to tell browsers not to cache certain pages. The following snippet works quite well on the browsers that are likely to visit your site:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code>header</code></span><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Cache-Control: no-cache, no-store, must-revalidate&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><code><span style="font-size:10pt;color:#666666;">//HTTP/1.1 </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Expires: </span></code><code><span style="font-size:10pt;color:#dd0000;">Sun, 01 Jul 2005</span></code><code><span style="font-size:10pt;color:#dd0000;"> </span></code><code><span style="font-size:10pt;color:#dd0000;">00:00:00</span></code><code><span style="font-size:10pt;color:#dd0000;"> GMT&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Pragma: no-cache&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><code><span style="font-size:10pt;color:#666666;">//HTTP/1.0 </span></code><span style="font-size:10pt;"><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code><code><span style="font-size:10pt;"> </span></code></p>
<p>The <code><span style="font-size:10pt;">Expires</span></code> header can be any date in the past. As with MIME types, browsers (especially older ones) may not always listen properly to your caching instructions (although most modern ones will).</p>
<h3>Other Applications</h3>
<p>There are other ways you can use headers as well, such as setting the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Response Code</a>, or in performing <a href="http://www.php.net/manual/features.http-auth.php">HTTP Authentication</a> (if you are running PHP as an Apache module). Now that you understand how <code><span style="font-size:10pt;">header()</span></code> works and how to use it, you&#8217;ll be able to do all sorts of things you might not have thought of before.</p>
<h2><a id="requestheaders" name="requestheaders"></a>Request Headers in PHP</h2>
<p>We&#8217;ve covered some of the things you can do with response headers above. We can also get a great deal of information from the request headers received by the server from the browser. There are two ways to access these. First, many of the values in the <a href="http://www.php.net/reserved.variables"><code><span style="font-size:10pt;">$_SERVER</span></code> array</a> are determined from the request headers. Second, if PHP is installed as an Apache module, then <a href="http://www.php.net/manual/function.apache-request-headers.php">apache_request_headers()</a> will return an array of all request headers (even those not in <code><span style="font-size:10pt;">$_SERVER</span></code>).</p>
<h3>Security first: don&#8217;t trust request headers</h3>
<p>Since request headers are set by the browser, which is controlled by the client, <strong>you must never trust request headers for information that is important to the security of your site</strong>. A good example is the <code><span style="font-size:10pt;">$_SERVER['HTTP_REFERER']</span></code> variable, which <em>should</em> hold the URL of the page that referred the user to the current one. A common mistake among beginners is to think that they can use this to make sure that users only access pages through a certain path, and that they therefore do not need to worry about server side data validation. For example, consider this code, which attempts to make sure that data has been submitted from a specific page, rather than a custom form on another website:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;color:#0000bb;">&lt;?php </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#007700;">if(</span></code><code><span style="font-size:10pt;color:#0000bb;">$_SERVER</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'HTTP_REFERER'</span></code><code><span style="font-size:10pt;color:#007700;">] != </span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;http://www.mysite.com/myform.html&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">){ </span></code><span style="font-size:10pt;"><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">header</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#dd0000;">&#8216;Refresh: 5; url=http://www.mysite.com/myform.html&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">); </span></code><span style="font-size:10pt;"><br />
<code> echo </code></span><code><span style="font-size:10pt;color:#dd0000;">&#8216;You must use the form on my site&#8230;redirecting now.&#8217;</span></code><code><span style="font-size:10pt;color:#007700;">; </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
<code> else{ </code><br />
<code> </code></span><code><span style="font-size:10pt;color:#0000bb;">insert_data</span></code><code><span style="font-size:10pt;color:#007700;">(</span></code><code><span style="font-size:10pt;color:#0000bb;">$_POST</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'var1'</span></code><code><span style="font-size:10pt;color:#007700;">], </span></code><code><span style="font-size:10pt;color:#0000bb;">$_POST</span></code><code><span style="font-size:10pt;color:#007700;">[</span></code><code><span style="font-size:10pt;color:#dd0000;">'var2'</span></code><code><span style="font-size:10pt;color:#007700;">]); </span></code><span style="font-size:10pt;"><br />
<code> } </code><br />
</span><code><span style="font-size:10pt;color:#0000bb;">?&gt;</span></code><code><span style="font-size:10pt;color:black;"> </span></code><code><span style="font-size:10pt;"> </span></code></p>
<p>This might work to deter an unsophisticated hacker who is using his web browser to submit data through a custom form, but someone who is a little more savvy could easily submit data via a telnet session like we did above, including the request header</p>
<p class="MsoNormal"><code><span style="font-size:10pt;">Referer: http://www.mysite.com/myform.html</span></code></p>
<p>and easily defeat this &#8216;protection&#8217;. The moral of the story is: use HTTP request headers to gather statistics and to help make the user experience more pleasant — most request headers you receive will be supplied by standard browsers and will be entirely truthful&#8230;But <strong>do not</strong> rely on request headers for any issues pertaining to security.</p>
<h3>Using HTTP request headers</h3>
<p>There are several things you can do with these. Using <code><span style="font-size:10pt;">$_SERVER['HTTP_USER_AGENT']</span></code> you can detect the type of browser the user says it has. You might check the <code><span style="font-size:10pt;">$_SERVER['HTTP_ACCEPT_LANGUAGE']</span></code> (perhaps along with <code><span style="font-size:10pt;">$_SERVER['HTTP_ACCEPT_CHARSET']</span></code> and some <a href="http://www.expertsrt.com/articles/Rod/city_country_IP.php">IP address geolocation</a>) to help determine the best language in which to serve your pages to a given user. Although <code><span style="font-size:10pt;">$_SERVER['HTTP_REFERER']</span></code> is not reliable for security purposes, it could be useful as an aid for building statistics about your website traffic or customizing content to match the path the user took to reach a given page. If for some reason you want to manipulate the raw query string used when the page was accessed, you can look in <code><span style="font-size:10pt;">$_SERVER['QUERY_STRING']</span></code>. Looking in <code><span style="font-size:10pt;">$_SERVER['REQUEST_METHOD']</span></code> will tell you whether your page was accessed via <code><span style="font-size:10pt;">GET</span></code> or <code><span style="font-size:10pt;">POST</span></code>. There&#8217;s quite a bit of information there for you to find creative uses for. <a id="metaequiv" name="metaequiv"></a></p>
<h2>HTML Meta Tag HTTP Header Equivalents</h2>
<p>Chances are, before reading this article, you have seen or used the HTML meta tag below to redirect a user:</p>
<p class="MsoNormal"><code><span style="font-size:10pt;">&lt;meta http-equiv=&#8221;refresh&#8221; content=&#8221;0;http://www.mysite.com/somepage.html&#8221; /&gt;</span></code></p>
<p>Look familiar? The &#8216;http-equiv&#8217; meta tags are &#8216;equivalent&#8217; to HTTP response headers, and were introduced so that people writing HTML pages without server side programming would have access to the powerful functionality described above. Using these meta tags is simple: they can be placed anywhere in the <code><span style="font-size:10pt;">&lt;head&gt;</span></code> of the document, and their <code><span style="font-size:10pt;">http-equiv</span></code> attribute contains the header name, while the <code><span style="font-size:10pt;">content</span></code> attribute contains the value for the header.</p>
<p>I&#8217;ve found that these, like the HTTP headers in general, often produce confusion, but now they should seem quite simple to you. Although I usually prefer to use the PHP <code><span style="font-size:10pt;">header()</span></code> function, these meta tag HTTP header equivalents are often very handy for things like specifying the character set. For example, I often use this is my HTML pages (and sometimes my PHP ones):</p>
<p class="MsoNormal"><code><span style="font-size:10pt;">&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=utf-8&#8243; /&gt;</span></code></p>
<p class="MsoNormal"><strong>Note:</strong> Support for HTTP headers as equivalet meta tags is not uniformally supported, so it is usually safer and faster to use the headers themselves if you can. Also, it should be obvious that some headers and values will not work as meta equivalents: you cannot set the <code><span style="font-size:10pt;">Content-Type</span></code> to <code><span style="font-size:10pt;">image/png</span></code> when the real headers have been sent and the browser is already reading the HTML <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<h2><a id="conclusion" name="conclusion"></a>Conclusion</h2>
<p>Now that you are done with this article, you should have a pretty firm grasp of how HTTP works, how request and response headers are used, and how you can employ this functionality in your programming. This reasonably detailed knowledge should also enable you to start thinking more critically about your web application efficiency and security. I hope that as you move forward with your programming, you will find that you&#8217;ve become quite comfortable working with HTTP headers, and that you are able to exploit them to make your job easier and your pages better.</p>
<p>As a parting thought, remember that headers are like words: they convey information and ask for certain actions to be performed, but by themselves they don&#8217;t force anything to happen. 99.9% of the time, cooperative browsers are talking to cooperative servers, and everything happens smoothly. But you have to remember that, as in life, every once in a while you&#8217;ll run across a jerk (a hacker), or someone who&#8217;s got his own way of doing things (Internet Explorer). Web development is very much a job of customer service, so you&#8217;ve got to do your best to keep the crooks out, and accomodate the customers with &#8217;special needs.&#8217; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p class="MsoNormal">
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ranacse05.wordpress.com/67/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ranacse05.wordpress.com/67/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ranacse05.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ranacse05.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ranacse05.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ranacse05.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ranacse05.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ranacse05.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ranacse05.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ranacse05.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ranacse05.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ranacse05.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ranacse05.wordpress.com&blog=1781316&post=67&subd=ranacse05&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ranacse05.wordpress.com/2008/04/28/header-tutorial/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/ranacse05-128.jpg" medium="image">
			<media:title type="html">rana</media:title>
		</media:content>
	</item>
	</channel>
</rss>