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

<channel>
	<title>code-diesel &#187; browser</title>
	<atom:link href="http://www.codediesel.com/category/browser/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Sharing data across windows using localStorage</title>
		<link>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/</link>
		<comments>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 07:28:39 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2832</guid>
		<description><![CDATA[One of a common requirement in some web applications is that of sending messages and data across windows (of the same origin). Doing this is not easy and requires the help of cookies and a bit of JavaScript. Now with HTML5 and its localStorage feature we can accomplish this quite easily. Storage Events Whenever a [...]]]></description>
			<content:encoded><![CDATA[<p>One of a common requirement in some web applications is that of sending messages and data across windows (of the same origin). Doing this is not easy and requires the help of cookies and a bit of JavaScript. Now with HTML5 and its localStorage feature we can accomplish this quite easily.<br />
<span id="more-2832"></span></p>
<h4>Storage Events</h4>
<p>Whenever a <em>localStorage</em> object is changed using the <em>setItem()</em>, <em>removeItem()</em>, or <em>clear()</em> functions, the <em>storage</em> event is fired (across multiple windows of the same origin) by the browser, we can trap this event and use it to share messages or data across windows. Check the following demo to see how this works in a simple case.</p>
<p><a href="http://www.codediesel.com/demos/localstorage/index.php"class="view_demo"  target="_blank"></a></p>
<p>The above example works by using the storage event of the Window object. So whenever the localStorage object is modified, the <em>storage</em> event is fired and we use it to update the window content.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/06/localstorage.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/06/localstorage.gif" alt="" title="localstorage" width="437" height="361" class="aligncenter size-full wp-image-2834" /></a></p>

<div class="wp_codebox"><table><tr id="p28324"><td class="code" id="p2832code4"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;storage&quot;</span><span style="color: #339933;">,</span> displayStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Below is the skeleton code for the demo example.</p>

<div class="wp_codebox"><table><tr id="p28325"><td class="code" id="p2832code5"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Input element</span>
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Element to display the updated data</span>
<span style="color: #003366; font-weight: bold;">var</span> output <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'event-data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> displayStorageEvent<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">key</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'storage-event'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        output.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">newValue</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> updateStorageEvent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'storage-event'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;storage&quot;</span><span style="color: #339933;">,</span> displayStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;keyup&quot;</span><span style="color: #339933;">,</span> updateStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Sharing messages</h4>
<p>Although in the above example we are sharing data across windows, we can use the same mechanism to share messages. In the above example we are using the &#8216;storage-event&#8217; key to store the data we type in the input box. Instead we can pass a simple message. The syntax remains the same, only the semantics changes.</p>

<div class="wp_codebox"><table><tr id="p28326"><td class="code" id="p2832code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Store the 'checkPassword' message in the 'app.message.auth' key */</span>
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'app.message.auth'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;checkPassword&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* Store the 'dataSave' message in the 'app.message.status' key */</span>
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'app.message.status'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;dataSave&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Security concerns</h4>
<p>As the communication can only happen between windows with the same origin, there is little risk of data leak between sites. Still you should refrain from storing sensitive information in the storage.</p>
<h4>Possible applications</h4>
<p>Now that we have seen a simple proof of concept of &#8216;cross window messaging and data sharing&#8217;, what are the potential use cases of the same. An idea without a concrete and useful application is useless. Although many people will have good ideas for the above concept, I presently lack one. So if you can think of some nice use cases for this, please voice your ideas in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peeking inside FireFox using MozRepl</title>
		<link>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/</link>
		<comments>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 13:06:43 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2655</guid>
		<description><![CDATA[I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools [...]]]></description>
			<content:encoded><![CDATA[<p>I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools at your disposal. The one I think you will find useful is MozRepl. With it you can connect to Firefox and other Mozilla apps, explore and modify them from the inside, execute Javascript, peek into HTML pages, examine functions and variables, all while FireFox is running.<br />
<span id="more-2655"></span><br />
<a href="https://github.com/bard/mozrepl/wiki#Emacs" rel="nofollow" target="_blank" >MozRepl</a> &#8211; a read-eval-print loop for Firefox &#8211; is a Firefox extension that acts like a TCP/IP socket server within Firefox. You can then connect to the socket using any client application and send commands to Firefox. Each command you send to Firefox using MozRepl is executed as if it was run from the browser, which gives you the ability to do anything that you would normally do using Javascript.</p>
<h4>Installing MozRepl</h4>
<p>Before proceeding you need to first install MozRepl which comes as a Firefox extension.  Head over to <a href="https://github.com/bard/mozrepl/wiki/" rel="nofollow" target="_blank" >github</a> to download and install. Once you have installed it, go to Firefox Tools menu and select MozLab → Start MozRepl. MozRepl will now be listening for connections on the default port 4242.</p>
<h4>Connecting to MozRepl</h4>
<p>Now that we have MozRepl up and running we can easily connect to it using Telnet. By default MozRepl listens on port 4242, which however you can change to your liking from the MozRepl menu.</p>

<div class="wp_codebox"><table><tr id="p265516"><td class="code" id="p2655code16"><pre class="text" style="font-family:monospace;">C:\&gt; telnet localhost 4242</pre></td></tr></table></div>

<p>You will get the following response if you are correctly connected to MozRepl.</p>

<div class="wp_codebox"><table><tr id="p265517"><td class="code" id="p2655code17"><pre class="text" style="font-family:monospace;">Welcome to MozRepl.
 - If you get stuck at the &quot;...&gt;&quot; prompt, enter a semicolon (;) 
at the beginning of the line to force evaluation.
 - If you get errors after every character you type, see http://github.c
om/bard/mozrepl/wikis/troubleshooting (short version: stop using 
Microsoft telnet, use netcat or putty instead)
Current working context: chrome://browser/content/browser.xul
Current input mode: syntax
&nbsp;
repl&gt;</pre></td></tr></table></div>

<p>If you have trouble connecting using Windows telnet or encounter some inconsistent behavior,  you can use <a href="http://www.putty.org/" rel="nofollow" >Putty</a> instead. A typical putty connection setup is shown below, note the &#8216;telnet&#8217; radio selection:</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png"><img src="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png" alt="" title="putty" width="453" height="440" class="aligncenter size-full wp-image-2657" /></a></p>
<p>Also make sure you check the &#8216;Implicit CR in every LF&#8217; check box.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif" alt="" title="putty-config" width="455" height="441" class="aligncenter size-full wp-image-2770" /></a></p>
<p>Once you are connected to the server you will be presented with the following prompt:</p>

<div class="wp_codebox"><table><tr id="p265518"><td class="code" id="p2655code18"><pre class="text" style="font-family:monospace;">repl&gt;</pre></td></tr></table></div>

<p>Lets try a standard greeting.</p>

<div class="wp_codebox"><table><tr id="p265519"><td class="code" id="p2655code19"><pre class="text" style="font-family:monospace;">repl&gt; window.alert(&quot;Hello World!&quot;)</pre></td></tr></table></div>

<p>MozRepl is now ready to accepts your commands. Lets try a simple one given below. The first line is the command we send to MozRepl to get the title of the current open Firefox window, while the second line is the response.</p>

<div class="wp_codebox"><table><tr id="p265520"><td class="code" id="p2655code20"><pre class="text" style="font-family:monospace;">repl&gt; document.title
&quot;Tutorial - mozrepl - GitHub - Mozilla Firefox&quot;</pre></td></tr></table></div>

<p>Lets try changing the document title of the current Firefox window:</p>

<div class="wp_codebox"><table><tr id="p265521"><td class="code" id="p2655code21"><pre class="text" style="font-family:monospace;">repl&gt; document.title = &quot;hello&quot;</pre></td></tr></table></div>

<p>Use the following to get all the function and variables in Firefox:</p>

<div class="wp_codebox"><table><tr id="p265522"><td class="code" id="p2655code22"><pre class="text" style="font-family:monospace;">repl&gt; repl.look()</pre></td></tr></table></div>

<p>This is just a sampler, you can do a whole lot of things using MozRepl, check this <a href="http://www.youtube.com/watch?v=5RSnHN6S52c" rel="nofollow" target="_blank" >video</a> for some more examples.</p>
<h4>Connecting to MozRepl with PHP</h4>
<p>As MozRepl creates a server on port 4242, we can easily connect to it via PHP and send commands to it. A small example is given below which you will need to run from the command line. The following code sends 3 commands to the MozRepl server and prints the responses. It uses the <em>socketHelper</em> class to do the dirty work of socket processing.</p>

<div class="wp_codebox"><table><tr id="p265523"><td class="code" id="p2655code23"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'socketHelper.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Commands to send to  MozRepl */</span>
&nbsp;
<span style="color: #000088;">$commands</span><span style="color: #339933;">=</span><span style="color: #009933; font-style: italic;">&lt;&lt;&lt;EOD
repl.whereAmI()
content.location.href = 'http://google.com'
repl.quit()
EOD</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$firefox_socket</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketHelper<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$commands</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//Skip blank lines</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send_command</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Code for <em>socketHelper</em> class</p>

<div class="wp_codebox"><table><tr id="p265524"><td class="code" id="p2655code24"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* socketHelper.php */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SocketHelper
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$port</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4242&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$socket</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_create</span><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span>SOCK_STREAM<span style="color: #339933;">,</span>SOL_TCP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">socket_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/** Send a command to MozRepl */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> send_command<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$command</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">socket_write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #009933; font-style: italic;">/* 
        Read from the Socket until we get a &quot;repl&gt;&quot; prompt, 
        or loop forever.
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> read<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$chunk</span> <span style="color: #339933;">=</span> <span style="color: #990000;">socket_read</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">65536</span><span style="color: #339933;">,</span>PHP_BINARY_READ<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Error reading from socket<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//No more data</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|^(.*)\s*repl\d*&gt;\s*$|s'</span><span style="color: #339933;">,</span><span style="color: #000088;">$chunk</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$chunk</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Security Warning</h4>
<p>Because MozRepl can directly poke inside FireFox it can practically work with anything &#8211; your bookmarks, cookies, cache etc, so security should be your prime concern. So do not ever allow outside connections in MozRepl (Tools menu → MozLab → Allow outside connections), unless you are sure what you are doing.</p>
<p>I&#8217;m still investigating the things I can do with MozRepl. If you have done some cool things of your own using it, please post your ideas here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>For whom do we develop software!</title>
		<link>http://www.codediesel.com/browser/for-whom-do-we-develop-software/</link>
		<comments>http://www.codediesel.com/browser/for-whom-do-we-develop-software/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 03:15:51 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[interface]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/general/these-are-your-users/</guid>
		<description><![CDATA[interface design as an important part of software development]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2010/04/badaman_hands_on_clay.png"><img src="http://www.codediesel.com/wp-content/uploads/2010/04/badaman_hands_on_clay.png" alt="badaman_hands_on_clay" title="badaman_hands_on_clay" width="90" height="66" class="alignleft size-full wp-image-2649" style="border: none;" /></a>Interface design is hard. Which is why most programmers turn a blind eye to it. During collaborative development I frequently encounter fellow programmers remark something to the following effect: &#8216;<em>&#8230;do not worry, the users are not idiots, they will understand for what these buttons have been provided, no need to provide tool-tips or any help, lets get these code working and show it to the client</em>.&#8217;<br />
Interface design or rather usability design is usually left as an after thought; a colorful facade that you stick on to your backend code.</p>
<p>The following two videos provide a stark reminder, that for most of the time these are the people we develop software for.<br />
<span id="more-2648"></span><br />
<object width="500" height="280"><param name="movie" value="http://www.youtube.com/v/o4MwTvtyrUQ&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/o4MwTvtyrUQ&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="280"></embed></object></p>
<p><object width="500" height="280"><param name="movie" value="http://www.youtube.com/v/lEt0N3xu0Do&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/lEt0N3xu0Do&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="280"></embed></object></p>
<p>Although the above videos are in the context of the users familiarity with the concept of a browser, it brings home the point that for the user the interface is everything, which most of us developers give little thought. Most users don&#8217;t care what browser or the version thereof they are using, they just need to get the work done somehow.</p>
<p>People are not idiots as the above videos may have you believe, on the contrary we developers are not smart enough to create usable software. </p>
<p>Writing software, once we become comfortable with the language and environment is easy. But crafting software that the user will love and admire is a lot harder, which in the end is what really matters. Not that I&#8217;m downplaying the importance of good code &#8211; testing, security, code efficiency are all important elements of a good product. But for the user, <em>the interface is the product</em>.  Apple seems to get it, so why can&#8217;t everyone.</p>
<p>The path out of this quandary is to really <em>understand </em> usability. If you are a freelancer developer get some good books on interface design and usability, read them, try to implement as much good interface designs into your current project as you possibly can. Over time this will become almost second nature to you. Below are some of the books related to good interface designs that I personally like:</p>
<p><a href="http://www.amazon.com/Dont-Make-Me-Think-Usability/dp/0321344758/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1272343205&#038;sr=8-1" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2010/04/dontmakemethink.jpeg" alt="don't make me think" title="don't make me think" width="101" height="130" class="alignleft size-full wp-image-2650" /></a><a href="http://www.amazon.com/Designing-Interfaces-Patterns-Effective-Interaction/dp/0596008031/ref=sr_1_26?ie=UTF8&#038;s=books&#038;qid=1272343557&#038;sr=8-26" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2010/04/designing-interfaces.jpeg" alt="designing-interfaces" title="designing-interfaces" width="101" height="130" class="alignleft size-full wp-image-2651" /></a><a href="http://www.amazon.com/Effective-UI-ebook/dp/B003AU7DPC/ref=sr_1_2?ie=UTF8&#038;m=AH9CGK6QR37LL&#038;s=digital-text&#038;qid=1272344179&#038;sr=8-2" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2010/04/effectiveui.jpg" alt="effectiveui" title="effectiveui" width="101" height="130" class="alignleft size-full wp-image-2652" /></a><a href="http://www.amazon.com/Design-Everyday-Things-Donald-Norman/dp/0465067107/ref=sr_1_2?ie=UTF8&#038;s=books&#038;qid=1272345314&#038;sr=8-2" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2010/04/designofeverydaythings.jpg" alt="designofeverydaythings" title="designofeverydaythings" width="90" height="130" class="alignleft size-full wp-image-2653" /></a></p>
<p>Many readers will be surprised by the absence of Coopers&#8217; <a href="http://www.amazon.com/About-Face-Essentials-Interaction-Design/dp/0470084111/ref=sr_1_7?ie=UTF8&#038;s=books&#038;qid=1272344671&#038;sr=8-7" rel="nofollow" >About Face 3</a> here. Coopers&#8217; is a decent book, but I somehow do not like it. It is a tad wordy and preachy, most of which I do not agree on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/browser/for-whom-do-we-develop-software/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Detecting user agents in php</title>
		<link>http://www.codediesel.com/pear/detecting-user-agents-in-php/</link>
		<comments>http://www.codediesel.com/pear/detecting-user-agents-in-php/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 13:48:29 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[agents]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1660</guid>
		<description><![CDATA[how to detect browser agents in php]]></description>
			<content:encoded><![CDATA[<p>Every time you use your browser to access a website a User-Agent header is sent to the respective server.<br />
Detecting user agents on the server can be useful for many reasons. </p>
<p>1. Browsers Quirks – Despite the standardization in browsers, there will remain some quirks in various browsers that you will need to iron out on a regular basis.<br />
2. Personalize Content – It may be required to deliver different type of content depending on the browser type (although it is usually not recommended); whether mobile or otherwise.<br />
3. Illegal Access – Prevent bandwidth hogging bots and poorly programmed clients from downloading your content.<br />
<span id="more-1660"></span><br />
Below is a sample header for my site when using Firefox.</p>

<div class="wp_codebox"><table><tr id="p166025"><td class="code" id="p1660code25"><pre class="text" style="font-family:monospace;">http://www.codediesel.com/
&nbsp;
GET / HTTP/1.1
Host: www.codediesel.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6)
Gecko/2009011913 Firefox/3.0.6 FirePHP/0.2.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive</pre></td></tr></table></div>

<p>PHP already has a builtin function &#8211; <a href="http://us2.php.net/manual/en/function.get-browser.php" rel="nofollow" target="_blank" >get_browser()</a> that lets you determine the capabilities of the user&#8217;s browser, but it requires a browscap.ini to be installed, which sadly is not bundled with PHP, and also the function can slow down your php script. The other way to get a user agent is to use php server variables like below,</p>

<div class="wp_codebox"><table><tr id="p166026"><td class="code" id="p1660code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In this post we will use the <a href="http://pear.php.net/package/net_useragent_detect/redirected" rel="nofollow" target="_blank" >Net_UserAgent_Detect</a> Pear package to determine user agents.</p>
<h4>Installation</h4>
<p>Net_UserAgent_Detect being a Pear package we will use the Pear installer as below. I recommend to always use the Pear installer to download packages rather than downloading it manually as the Pear installer automatically downloads any dependent packages.</p>

<div class="wp_codebox"><table><tr id="p166027"><td class="code" id="p1660code27"><pre class="text" style="font-family:monospace;">pear install Net_UserAgent_Detect-2.5.1</pre></td></tr></table></div>

<h4>Usage</h4>
<p>Usage is quite simple. For example the following code:</p>

<div class="wp_codebox"><table><tr id="p166028"><td class="code" id="p1660code28"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'Net/UserAgent/Detect.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> Net_UserAgent_Detect<span style="color: #339933;">::</span><span style="color: #004000;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>will return the following string on Firefox 3.0.6: This can be quite useful if you need to log the users browser or OS type.</p>

<div class="wp_codebox"><table><tr id="p166029"><td class="code" id="p1660code29"><pre class="text" style="font-family:monospace;">Mozilla/5.0 (Windows; U; Windows NT 5.1; 
en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 FirePHP/0.2.4</pre></td></tr></table></div>

<p>getUserAgent() is only one of the many methods available in the class.</p>

<div class="wp_codebox"><table><tr id="p166030"><td class="code" id="p1660code30"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'Net/UserAgent/Detect.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Browser String: '</span><span style="color: #339933;">.</span>Net_UserAgent_Detect<span style="color: #339933;">::</span><span style="color: #004000;">getBrowserString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OS String: '</span><span style="color: #339933;">.</span>Net_UserAgent_Detect<span style="color: #339933;">::</span><span style="color: #004000;">getOSString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Javascript: '</span><span style="color: #339933;">.</span>Net_UserAgent_Detect<span style="color: #339933;">::</span><span style="color: #004000;">getFeature</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Some other useful functions to directly test the type of browser are:<br />
isIE()<br />
isNavigator( )<br />
isNetscape( )</p>
<p>So to detect if the user is running Firefox:</p>

<div class="wp_codebox"><table><tr id="p166031"><td class="code" id="p1660code31"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> Net_UserAgent_Detect<span style="color: #339933;">::</span><span style="color: #004000;">isNetscape</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/pear/detecting-user-agents-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Opera Unite : A web server in your browser</title>
		<link>http://www.codediesel.com/browser/opera-unite-a-web-server-in-your-browser/</link>
		<comments>http://www.codediesel.com/browser/opera-unite-a-web-server-in-your-browser/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 06:32:07 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1065</guid>
		<description><![CDATA[opera unite offers a web server in your browser]]></description>
			<content:encoded><![CDATA[<p>Rarely do I get excited about new software developments. The last I remember was when <a href="http://www.wolframalpha.com/index.html" rel="nofollow"  target="_blank">WolframAlpha</a> was realeased. Now it is <a href="http://unite.opera.com/" rel="nofollow" target="_blank" >Opera Unite</a>. I&#8217;ve forever been a Opera fan, and always loved the extra bit of functionality thoughtfully added to the product by the opera team. But Unite really takes the step forward.<br />
<span id="more-1065"></span><br />
In a nutshell, Opera Unite is a collaborative technology that uses a web server embedded inside the Opera browser to share data and services with the outside world. To share pictures, movies and other content right off your hard disk all you have to do is run the relevant Unite Service and then send the resulting link to your peers, with which they can than access your content. You can also write your own Opera applications in JavaScript, known as <em>Opera Unite Services</em>, which are then run by the Opera server. </p>
<p><strong>Basic Works</strong><br />
Opera Unite works by using a proxy server (operaunite.com) between the opera server and the various clients. This means besides your login credentials it takes zero configuration to connect to the outside world. There have been various attempts before for such collaborative tools, but the seamless integration provided by Unite makes it very  easier for people to collaborate and share content with other people.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/06/drawing1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/06/drawing1.gif" alt="opera unite" title="opera unite" width="540" height="207" class="aligncenter size-full wp-image-1081" /></a></p>
<p><strong>So what can you do with Unite:</strong><br />
1. You could play interactive games with your friends.<br />
2. Share photos, music and videos with other people, straight off your hard drive.<br />
3. You can work collaboratively with others on documents with your peers.<br />
or create whatever collaborative application you like using the Unite API.</p>
<p>The default Unite services shipped with Opera are as follows:</p>
<p>a. File Sharing<br />
Securely share a file from your personal computer without waiting to upload it. First select the folder from which you would like to share files. Opera Unite then generates a direct URL to that folder. By giving that link to your friends, you can share files without routing through a third-party Web service.</p>
<p>b.Web Server<br />
Run entire Web sites from your local computer with the Opera Unite Web Server. After selecting the folder containing your Web site, you can share and host it from the given Opera Unite URL. Opera Unite will automatically recognize index files and create the Web site as you designed it.</p>
<p>c.Media Player<br />
Rock out wherever you are by accessing your MP3s and playlists from any machine. After selecting the folder containing your playlist, use the Opera Unite direct link to play your tracks directly in any modern Web browser.</p>
<p>d.Photo Sharing<br />
Share your photos direct from your PC, without uploading them online. Once you select your photo folder, the photo-sharing service will create a thumbnail image gallery of your photos. Clicking the thumbnail will present the photo in its original resolution.</p>
<p>e.The Lounge<br />
The Lounge is a self-contained chat service running on your computer. Your friends can access the chat room via the direct link, which will not require them to sign into any service. Depending on your privacy settings, you need only provide the generated password to your service in order for people to log in to your chatroom.</p>
<p>f.Fridge<br />
Post a note on your friends’ virtual refrigerators. By sharing the direct link to your refrigerator, you and your friends, family or colleagues can exchange notes securely and privately in real time.</p>
<p><strong>Security</strong><br />
Unite provides nice and simple security features when sharing your content with the outside world. Naturally there still will be debates on the security implications of Unite; but leaving that aside Opera, by embedding a webserver in the browser, has dared to change more then a decade old model of a web browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/browser/opera-unite-a-web-server-in-your-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Codediesel Firefox toolbar</title>
		<link>http://www.codediesel.com/tools/codediesel-firefox-toolbar/</link>
		<comments>http://www.codediesel.com/tools/codediesel-firefox-toolbar/#comments</comments>
		<pubDate>Tue, 19 May 2009 14:23:14 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=874</guid>
		<description><![CDATA[Firefox toolbar]]></description>
			<content:encoded><![CDATA[<p>A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. The toolbar is shown below. You can install the same from </a><a href="/data/code/codediesel_toolbar.php" rel="nofollow" title="Install" >here</a>.</p>
<p><a href="/data/code/codediesel_toolbar.php" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2009/05/toolbar.gif" alt="Install" title="Install" width="546" height="24" class="aligncenter size-full wp-image-940" /></a></p>
<p>Now you can create a toolbar for your own blog or site. The source for the toolbar can be downloaded from below after which you can edit the code to suit your site; to help you there is a nice reference for XUL elements <a href="https://developer.mozilla.org/en/XUL" rel="nofollow" target="_blank" >here</a>. The idea for the post was inspired by <a href="http://davidwalsh.name/" rel="nofollow" target="_blank" >david</a>.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/codedieselToolbar" rel="nofollow" >Download Source</a><br />
<span>Downloads : 552  / File size : 23.2 kB</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/codediesel-firefox-toolbar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pushing xpi mime content from php</title>
		<link>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/</link>
		<comments>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/#comments</comments>
		<pubDate>Fri, 15 May 2009 04:01:49 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[mime]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=880</guid>
		<description><![CDATA[A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. Once installed on my blog I wanted Firefox to recognize it as an addon and install it rather than displaying a &#8216;save/open&#8217; dialog. For that I needed to add the following directive to the servers .htaccess [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. Once installed on my blog I wanted Firefox to recognize it as an addon and install it rather than displaying a &#8216;save/open&#8217; dialog. For that I needed to add the following directive to the servers .htaccess file.<br />
<span id="more-880"></span></p>

<div class="wp_codebox"><table><tr id="p88034"><td class="code" id="p880code34"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AddType</span> application/x-xpinstall .xpi</pre></td></tr></table></div>

<p>But the problem was that my server (godaddy) for some mysterious reasons was not recognizing the above directive. Searching around I found that godaddy has some restrictions on the various htaccess directives (yuck!). After fiddling for some time I finally had to try another solution. </p>
<p>What the Apache &#8216;AddType&#8217; directive does is that it maps the given filename extension onto the specified MIME content type, so that the browser can understand what it is supposed to do with the content. If we could replicate that in PHP than we are good. A possible solution that worked for me is shown below. You can also use the idea for other MIME types.</p>

<div class="wp_codebox"><table><tr id="p88035"><td class="code" id="p880code35"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* File we want to send to the browser */</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;codediesel.xpi&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * The following header is required for browsers that do not
 * recognize the xpi extension. i.e all browsers other than Firefox.
 * This will display the familiar 'save/open' dialog if the xpi
 * extension is not supported.
 */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: filename=<span style="color: #006699; font-weight: bold;">{$filename}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* Tell the browser that the content that is coming is an xpinstall */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: application/x-xpinstall'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* Also send the content length */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Length: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* readfile reads the file content and echos it to the output */</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of course if the filesize is large the <em>readfile</em> function could possibly incur a performance hit. But for small files it works good.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Internet Explorer 8 and backward compatibility</title>
		<link>http://www.codediesel.com/browser/ie8-and-backward-compatibility/</link>
		<comments>http://www.codediesel.com/browser/ie8-and-backward-compatibility/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 15:44:44 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[ie8]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=522</guid>
		<description><![CDATA[With the release of Internet Explorer 8, the issue of compatibility has again become a concern for web developers. If your website does not display correctly in IE8, you have a choice of either updating your website to support the latest Web standards or you can force IE8 to display your content as if it [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.codediesel.com/wp-content/uploads/2009/03/ie8.gif" alt="ie8" title="ie8" width="77" height="77" class="alignleft size-full wp-image-531" />With the release of Internet Explorer 8, the issue of compatibility has again become a concern for web developers. If your website does not display correctly in IE8, you have a choice of either updating your website to support the latest Web standards or you can force IE8 to display your content as if it were being rendered in an older version of the browser. Luckily IE8 has a compatibility mode which tells IE what browser version it should use to render a page. This will give developers time to update their site for IE8.<br />
<span id="more-522"></span><br />
A quick fix is to add a meta tag on any page which you want to render as version 7 or below.</p>

<div class="wp_codebox"><table><tr id="p52237"><td class="code" id="p522code37"><pre class="html" style="font-family:monospace;">&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=EmulateIE7&quot; /&gt;</pre></td></tr></table></div>

<p>In the same way specify IE=5, IE=7, or IE=8 to select one of those compatibility modes. A complete table is given below.</p>
<p><img src="http://www.codediesel.com/wp-content/uploads/2009/03/modes.gif" alt="ie8 modes" title="ie8 modes" width="514" height="311" class="alignleft size-full wp-image-526" /></p>
<p><strong>Default Rendering in IE8</strong></p>
<p>So how does IE8 render pages by default. According to the Microsoft documentation, when Internet Explorer 8 encounters a Web page that does not contain an X-UA-Compatible header, it uses the <a href="http://en.wikipedia.org/wiki/Document_Type_Declaration" rel="nofollow" target=_blank" >DOCTYPE</a> directive to determine how to display the page. If the directive is missing or does not specify a standards-based document type, Internet Explorer 8 displays the page in IE5 mode (quirks mode).</p>
<p>If the <!DOCTYPE> directive specifies a standards-based document type, Internet Explorer 8 displays the page in IE8 mode, except in the following cases:</p>
<p>·         Compatibility View is enabled for the page.</p>
<p>·         The page is loaded in the Intranet zone and Internet Explorer 8 is configured to pages in the Intranet zone in Compatibility View.</p>
<p>·         Internet Explorer 8 is configured to display all Web sites in Compatibility View. </p>
<p>·         Internet Explorer 8 is configured to use the Compatibility View List, which specifies a set of Web sites that are always displayed in Compatibility View.</p>
<p>·         The Developer Tools are used to override the settings specified in the Web page. </p>
<p>·         The Web page encountered a page layout error and Internet Explorer 8 is configured to automatically recover from such errors by reopening the page in Compatibility View.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/browser/ie8-and-backward-compatibility/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

