<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>observances</title>
	
	<link>http://krahulg.wordpress.com</link>
	<description>web * programming * the higher end</description>
	<lastBuildDate>Fri, 19 Sep 2008 16:29:57 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain="krahulg.wordpress.com" port="80" path="/?rsscloud=notify" registerProcedure="" protocol="http-post" />
<image>
		<url>http://www.gravatar.com/blavatar/33f2e7462a62355b909d19e411c9000e?s=96&amp;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>observances</title>
		<link>http://krahulg.wordpress.com</link>
	</image>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Observances" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Web 2.0: The birth of Social Media and You</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/TGox1PTCxDI/</link>
		<comments>http://krahulg.wordpress.com/2008/09/19/web-20-the-birth-of-social-media-and-you/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 15:41:13 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Ranting]]></category>
		<category><![CDATA[barcamp]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[napster]]></category>
		<category><![CDATA[netscape]]></category>
		<category><![CDATA[patent]]></category>
		<category><![CDATA[revenue sharing]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[web 1.0]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web 3.0]]></category>
		<category><![CDATA[you]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/?p=52</guid>
		<description><![CDATA[This started off as a script for my talk at the upcoming BarCamp Delhi [register here] to be held on Oct 11-12 at IIT, New Delhi. Before we proceed any further here is a really motivating video about the whole Web 2.0 movement, and yes, it is a movement, an uprising, and nothing short of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=52&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fpeople%2FWeb_2_0_The_birth_of_Social_Media_and_You' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe>This started off as a script for my talk at the upcoming <a href="http://barcampdelhi.com/" target="_blank">BarCamp Delhi</a> [<a title="Register here" href="http://wiki.barcampdelhi.com/index.php?title=BCD5Campers" target="_blank">register here</a>] to be held on Oct 11-12 at IIT, New Delhi. Before we proceed any further here is a really motivating video about the whole Web 2.0 movement, and yes, it is a movement, an uprising, and nothing short of it[whole story after the jump].</p>
<p><span style="text-align:center; display: block;"><a href="http://krahulg.wordpress.com/2008/09/19/web-20-the-birth-of-social-media-and-you/"><img src="http://img.youtube.com/vi/RoWKkl5nA08/2.jpg" alt="" /></a></span></p>
<p>All online media, as well as most of offline media, has the following entities to the heart of it:</p>
<ul>
<li>Content Creators</li>
<li>Distribution Channel</li>
<li>Community/Audience</li>
</ul>
<p>Armed with those three points, we take a dive.</p>
<p><strong>Web 1.0:</strong> At the very beginning, that is the beginning of the Internet, there was too much consoling on consoles, very nerdy geeks[read <a title="Bill Gates, Microsoft" href="http://www.microsoft.com" target="_blank">gates</a> and <a title="Steve Jobs, Apple" href="http://www.apple.com" target="_blank">jobs</a>] having fun with computers as they were and just cooking up things that made the thing <a title="Windows" href="http://en.wikipedia.org/wiki/Windows" target="_blank">more</a> and <a title="Macintosh" href="http://en.wikipedia.org/wiki/Macintosh" target="_blank">more</a> usable. Then we had all the <a title="List of Operating Systems" href="http://en.wikipedia.org/wiki/List_of_operating_systems" target="_blank">operating systems</a> and <a title="History of computing platforms" href="http://en.wikipedia.org/wiki/History_of_computing_hardware_(1960s-present)" target="_blank">hardware platforms</a> we would ever need, really.</p>
<p>Now those were the days of infancy of big corporations in the computing industry and they showed no signs of amateurishness whatsoever. <a title="Bill Gates richest American for fifteen years in a row" href="http://www.reuters.com/article/rbssTechMediaTelecomNews/idUSN1748882920080917" target="_blank">Bill Gates is the richest american for fifteen years</a> in a row, so the seriousness we are talking about here is beyond grasp. It was clearly visible by <a title="Browser Wars" href="http://en.wikipedia.org/wiki/Browser_wars" target="_blank">how they fought</a> Netscape, a pretty innocent startup, that took the very first step in a never-to-die-down uprising. An uprising that is less surprised than its participators. Participators, who often have found themselves at the receiving end of this uprising. Netscape offered to provide, eh, documents(??) online. How innocent? That was the first browser that could display images inline with the text and with the help of some more wizardry that made this <a title="Topped the Top 50 products list by PC World" href="http://www.pcworld.com/article/130207-14/the_50_best_tech_products_of_all_time.html" target="_blank">revolutionary new browser</a> technology usable, it caught the fancy of the world, wide, web.</p>
<p>The social media here were the HTML documents. The creators were those few nerdy elites who knew something as exotic as HTML. So when we had the distribution channel in place and the creators were excited to create the very first form of social media that the world would know, Microsoft found something wrong. If the channel was let go of, Microsoft would lose monopoly of the very thing it built its empire on, the desktops. Whatever be the case, this uprising was muted, although for some time.</p>
<p>So the social media was there, the creators were in place, and the audience was present as well, but the distribution channel got choked. The users have been denied something that they could have had.</p>
<p>All is never lost. Just when the industry was making big money on this very nascent computing technology and the newest marvel of it, the Internet, lightning struck on the other side of the hamlet. <a title="Napster" href="http://en.wikipedia.org/wiki/Napster" target="_blank">Napster</a> was born, and what a birth. This time the blow would hurt even deeper, like it always does. Napster allowed anyone to get a song he/she liked from any part of the world in minutes, for free. Wow. So the new social media is a song, revolutionised by a <a title="MP3" href="http://en.wikipedia.org/wiki/MP3" target="_blank">new technology called MP3</a> which renders a song file very transferable over computer networks of the day. The creators of this new social media are the <a title="Metallica" href="http://en.wikipedia.org/wiki/Metallica" target="_blank">industry signed music artists</a>, very prized possession of the recording labels. And we know the size of the audience who are into music, its huge. Napster was the distribution channel and bang, again, <a title="A&amp;M Records, Inc. v. Napster, Inc." href="http://en.wikipedia.org/wiki/A%26M_Records,_Inc._v._Napster,_Inc." target="_blank">the industry finds something wrong</a> in this. Don&#8217;t you find something wrong here?? If I am a fan of something, I oughtta receive a souvenir for my faithfulness and not pay for it. And when someone does something that actually helps my faith grow, the very artists find it wrong?? Just doesn&#8217;t add up any which way I try.</p>
<p>Whichever way the jury settled, this was the birth of <a title="IP" href="http://en.wikipedia.org/wiki/Intellectual_property" target="_blank">Intellectual Property Rights</a>, patenting and much <a title="DMCA" href="http://en.wikipedia.org/wiki/Digital_Millennium_Copyright_Act" target="_blank">copyrighting</a> around the world. Now everything gets copyrighted to the creator and the owner.</p>
<p>As an aside, and before moving on to the next generation of Web revolution, here&#8217;s another case:Sit to think about what has been the primary conflict with Linux?? It is the distribution channel. Its open, wide open. You can come in anytime and if you want to, you can just pick off one single application and leave. It was that much open. But due to the sheer size, and the fact that the creators and audience are both among us, there&#8217;s nothing much the industry could do. That is a very geeky kind of social media, but it lived on.</p>
<p><strong>Web 2.0:</strong> So now, in the spirit of the video above, to hell with all artists. We have all the channels now to be the stars that we can be. Let <a title="Fifteen Minutes of Fame" href="http://en.wikipedia.org/wiki/15_minutes_of_fame" target="_blank">Warhol take a class for fifteen minutes</a> after which, we can start on our journey of claiming and entertaining our own audience. We have social bookmarking sites, wikis, video-sharing sites, blogging sites, picture sharing sites, social networks, microblogging, life streaming, virtual worlds, podcasting, webcasting, &#8230; the distribution channel has stopped looking like a wire or pipe and now looks like the world in itself. The creators are all of us. We have our <a title="Creative Commons" href="http://creativecommons.org/" target="_blank">copyrights</a>. We are the audience as well. But wait. Copyright?? I am no <a title="Metallica" href="http://www.metallica.com/" target="_blank">Metallica</a>, and neither am I <a title="Dilbert" href="http://www.dilbert.com">Scott Adams</a>, so who will steal my creation? And in an <a title="How big is the Internet" href="http://www.wisegeek.com/how-big-is-the-internet.htm" target="_blank">online population of 500mn people</a>, if someone does, I won&#8217;t know. The chances are grim. <a title="CopyScape" href="http://www.copyscape.com">Copyscape</a> and <a title="TinEye" href="http://www.tineye.com" target="_blank">TinEye</a> may help, but what the heck, even if I find out, what are the chances that the discovery of such theft will be profitable for me??</p>
<p><strong>Profitable.</strong></p>
<p>If I was Metallica, I am only 4-5 guys in the whole world, and my copyright is heavyweight. It makes big money across oceans. The recording company better lookout for all infringements. But I am also a <a title="Gary Arndt" href="http://everything-everywhere.com/" target="_blank">traveller</a> sharing his pictures on the Internet just like that with the same kind of copyrights. But if my copyright gets violated, there&#8217;s not much doing on the way from my hosting service. I am not big money, my copyright is featherweight, or worse, pea-weight. The hosting service is still making money from the ads that result by way of pageviews on my picture pages and god knows how many in my audience click on them, but I am benefitted by none.</p>
<p>Is something wrong again?? Wrong is, the creators now don&#8217;t get paid for their creations. People have always wanted it for free, so what the heck, Mr Website Owner says, give it away on a web page with some mumbo-jumbo passed for copyrights and lets keep the dime with ourselves. Should I, the creator, not get a cut for the traffic my creations brings to the website I am hosting my stuff on?? Or shouldn&#8217;t the website proactively sue someone for violating the copyright on my creations, something that I have trusted this website with??</p>
<p>The Social Media has come a full circle, from the 90s, when you were only the audience, to the NOW, when you are the artist and you are the fan. So is your copyright holding it all together for you?? Are you being paid for the Intellectual Property that you are generating and hosting it with somebody?? I will leave you with questions here and continue on this topic sometime later, but will definitely finish it before I go in for the talk at <a title="BarCamp Delhi" href="http://barcampdelhi.com/" target="_blank">BarCamp</a>, where it is scheduled.</p>
Posted in Ranting Tagged: barcamp, copyright, napster, netscape, patent, revenue sharing, social media, web 1.0, web 2.0, web 3.0, you <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=52&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2008/09/19/web-20-the-birth-of-social-media-and-you/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/RoWKkl5nA08/2.jpg" medium="image" />
	<feedburner:origLink>http://krahulg.wordpress.com/2008/09/19/web-20-the-birth-of-social-media-and-you/</feedburner:origLink></item>
		<item>
		<title>Why are all the tectonic faults vertical??</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/T7t35WzsCkc/</link>
		<comments>http://krahulg.wordpress.com/2008/08/20/why-are-all-the-tectonic-faults-vertical/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 22:54:18 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[Ranting]]></category>
		<category><![CDATA[earthquakes]]></category>
		<category><![CDATA[MATLAB]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[seismic activity]]></category>
		<category><![CDATA[tectonic faults]]></category>
		<category><![CDATA[tectonic plates]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/?p=43</guid>
		<description><![CDATA[I can&#8217;t really make my point here until you open the image below in a separate tab or something and view it in full size. This plot has been generated using earthquake data for the past hundred years from earthquake.usgs.gov and it was plotted on a world map representation using MATLAB. My question is posed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=43&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FWhy_are_all_the_tectonic_faults_vertical' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe>I can&#8217;t really make my point here until you open the image below in a separate tab or something and view it in full size. This plot has been generated using earthquake data for the past hundred years from <a title="Centennial Earthquake Catalog" href="http://earthquake.usgs.gov/research/data/centennial.php" target="_blank">earthquake.usgs.gov</a> and it was plotted on a world map representation using MATLAB. My question is posed in full glory beneath this image.</p>
<div id="attachment_44" class="wp-caption aligncenter" style="width: 490px"><a href="http://krahulg.files.wordpress.com/2008/08/world.jpg"><img class="size-full wp-image-44" src="http://krahulg.files.wordpress.com/2008/08/world.jpg?w=480&#038;h=337" alt="Tectonic Plates plotted with data from USGS using MATLAB" width="480" height="337" /></a><p class="wp-caption-text">Seismic Activity plotted with data from USGS using MATLAB</p></div>
<p>All the dots on this image are the epicentres of a recorded earthquake as per data from USGS. The more yellow a dot is, the more severe the earthquake that was recorded, so basically higher the Richter magnitude. Blue dots are relatively low magnitude ones.</p>
<p>From the image you can make out the African plate in the middle, the American plates to the left of it[you can see the California fault to the very left of the North American plate], and at the top-right corner of the image is Japan. So now you can make out some serious fault lines represented here as dense yellow dots.</p>
<p>My question is, <strong>Why are all the fault lines running from north to south, i.e., vertical, and not more like parallel to the equator?? Has this anything to do with the direction of earth&#8217;s rotation??</strong></p>
<p>Please leave your answers in the comments section below.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/43/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/43/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=43&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2008/08/20/why-are-all-the-tectonic-faults-vertical/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>

		<media:content url="http://krahulg.files.wordpress.com/2008/08/world.jpg" medium="image">
			<media:title type="html">Tectonic Plates plotted with data from USGS using MATLAB</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2008/08/20/why-are-all-the-tectonic-faults-vertical/</feedburner:origLink></item>
		<item>
		<title>Virtual Keyboard Login – Version wicked.evil [avoid screenshots]</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/85IZx4ejiu4/</link>
		<comments>http://krahulg.wordpress.com/2008/07/28/virtual-keyboard-login-version-wickedevil/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 08:55:25 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[This Works]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[virtual keyboard]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/?p=32</guid>
		<description><![CDATA[Ok, so we had virtual keyboards for some time on login pages being served worldwide. In fact so long that we had this. So we have virtual keyboards here again, and some smartness, some.
Earlier in this blog we covered some crypt way to send passwords to the server from the browser, and thanks to the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=32&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FVirtual_Keyboard_Login_avoid_screenshots_vulnerability' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe>Ok, so we had virtual keyboards for some time on login pages being served worldwide. In fact so long that we had <a href="http://www.tracingbug.com/index.php/articles/view/23.html" target="_blank">this</a>. So we have virtual keyboards here again, and some smartness, some.</p>
<p>Earlier in this blog we covered some <a href="http://krahulg.wordpress.com/2007/12/26/preparing-a-secure-login-form-with-php-javascript/" target="_blank">crypt way</a> to send passwords to the server from the browser, and thanks to the response, i feel motivated enough. Now we are onto making a virtual keyboard, and yeah, this is a proof-of-concept and you are free to take it to the moon alongwith you.</p>
<p>We are just going to blank out all buttons just before the user is going to click on one. Basically do a backgroundColor = fontColor on all buttons to make it difficult what is written on the buttons on mouseover and restore on mouseout. Normally a user figures out which button to click on and then positions the mouse on the button and clicks, so <strong>if the button is showing what is written on it, definitely some proof-of-concept program can take a snapshot of the web page to figure out which button was clicked on</strong>. We are just going to <strong>wipe the face of the button off</strong>. For some more fun, we are going to <strong>randomize the order of buttons</strong> at will by calling randomizekeys() and supplying the order of the keys as an argument. And yeah, the styling class is closely tied to the javascript functions, so keep that in mind while playing with styles or the javascript. So here we go[look at the <strong>onload handler in the body tag</strong>] &#8230;</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;

&lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"&gt;

    &lt;title&gt;Virtual Login Panel&lt;/title&gt;
    &lt;style&gt;
    .loginnumkey {
        background:#000;
        color:#FFF;
        padding:5px 0 5px 0;
        min-width:40px;
        font-size:16px;
        font-family:tahoma;
        margin:1px;
    }
    &lt;/style&gt;
    &lt;script&gt;
    function randomizekeys(assigncode, numkeysclass)
    {
        var j = 0;
        var els = document.getElementsByTagName('input');
        var elsLen = els.length;
        var pattern = new RegExp('\\b'+numkeysclass+'\\b');
        for (var i = 0; i &lt; elsLen; i++)
        {
            if ( pattern.test(els[i].className) &amp;&amp; j &lt; assigncode.length)
            {
                els[i].value = assigncode[j];
                j++;
            }
        }
    }
    function keysoff(numkeysclass)
    {
        var i = 0;
        var els = document.getElementsByTagName('input');
        var elsLen = els.length;
        var pattern = new RegExp('\\b'+numkeysclass+'\\b');
        for (i = 0; i &lt; elsLen; i++)
        {
            if ( pattern.test(els[i].className) )
            {
                els[i].style.backgroundColor = '#FFF';
            }
        }
    }
    function keyson(numkeysclass)
    {
        var i = 0;
        var els = document.getElementsByTagName('input');
        var elsLen = els.length;
        var pattern = new RegExp('\\b'+numkeysclass+'\\b');
        for (i = 0; i &lt; elsLen; i++)
        {
            if ( pattern.test(els[i].className) )
            {
                els[i].style.backgroundColor = '#000';
            }
        }
    }
    function clicknumkey(inputid, inputvalue)
    {
        document.getElementById(inputid).value =
		document.getElementById(inputid).value + inputvalue;
    }
    &lt;/script&gt;
&lt;/head&gt;

&lt;body onload="javascript:randomizekeys('1095673824', 'loginnumkey');"&gt;

    &lt;input type='text' id='passwordbox'&gt;
    &lt;br&gt;&lt;br&gt;
    &lt;input type='button' id='lkey1' value='1' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey2' value='2' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey3' value='3' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;br&gt;

    &lt;input type='button' id='lkey4' value='4' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey5' value='5' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey6' value='6' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;br&gt;

    &lt;input type='button' id='lkey7' value='7' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey8' value='8' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkey9' value='9' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;br&gt;

    &lt;input type='button' id='lkey0' value='0' class='loginnumkey'
    onclick="javascript:clicknumkey('passwordbox', this.value);"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

    &lt;input type='button' id='lkeyclear' value='reset' class='loginnumkey'
    onclick="javascript:document.getElementById('passwordbox').value='';"
    onmouseover="javascript:keysoff('loginnumkey');"
    onmouseout="javascript:keyson('loginnumkey');"&gt;

&lt;/body&gt;

&lt;/html&gt;</pre>
<p>This may not work in IE, I mean this code snippet. If you want to make it work, just fiddle with i, j declarations in the function randomizekeys(), like moving them around in the function.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=32&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2008/07/28/virtual-keyboard-login-version-wickedevil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2008/07/28/virtual-keyboard-login-version-wickedevil/</feedburner:origLink></item>
		<item>
		<title>Social Networking Websites – Revenue Models</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/NKKXvB9KDCQ/</link>
		<comments>http://krahulg.wordpress.com/2008/06/26/social-networking-websites-revenue-models/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 10:39:55 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Ranting]]></category>
		<category><![CDATA[adsense]]></category>
		<category><![CDATA[micro-payments]]></category>
		<category><![CDATA[monetizing]]></category>
		<category><![CDATA[revenue models]]></category>
		<category><![CDATA[revenue sharing]]></category>
		<category><![CDATA[social networking]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/?p=27</guid>
		<description><![CDATA[ Out of ten people I know, atleast one has asked me how are social networking sites profitable. Out of hundred people I know, atleast one is trying to erect a social networking site and is desperately trying to answer this question. I am talking about the second most popular question on earth after &#8220;Where [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=27&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fsoftware%2FSocial_Networking_Websites_Revenue_Models' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe> Out of ten people I know, atleast one has asked me how are social networking sites profitable. Out of hundred people I know, atleast one is trying to erect a social networking site and is desperately trying to answer this question. I am talking about the second most popular question on earth after &#8220;Where is God?&#8221;.</p>
<p><strong>How are social networking websites making money?</strong></p>
<p>If you are one who is trying to up a social networking website, I would like to share some gathered thoughts here about how one can monetize a social networking website and how one cannot, or if you know more, please use the comments section below, I am around and eager.</p>
<p><strong>Userbase is money</strong>: NO. Yahoo has 500mn users, and if this were true, you would know more about Jerry Yang than some Brinn or Page or Zuckerberg. Having a hugely popular website is not going to get you rich unless you have a revenue model already planned into it. So get out of this mindset, as this is the first no-brainer that a sales guy will throw at you if you asked him this question.</p>
<p><strong>I will put in Ads</strong>: I really don&#8217;t know which wise guy had this inundating brainwave of allocating real estate on web pages and charging businesses for the ads shown on them. This is not TV. I myself know, I haven&#8217;t clicked on a single ad till date, they are just not useful and they are not convincing enough. I am sorry AdSense, you are good, but I am sorry, in fact, ask tickle.com[the online IQ testing website] for some data about the users which came in from your ad clicks and how much was their IQ range, should be an eye-opener. Anyways, so people don&#8217;t read entire web pages from top to bottom, left to right, sequentially as if watching a TV, spending time with every commercial on it just because they can&#8217;t skip the commercial breaks. On web pages, people just navigate to the exact section and click. And with usability getting to ever higher levels and the content getting more relevant, users are almost hypnotized. You may find umpteen success stories about how per-click ad programs made people rich, but you have to find one yourself in this real world to be convinced, and you won&#8217;t find one<a href="http://www.askthevc.com/blog/archives/2007/11/ad-revenue-mode.php" target="_blank">[1]</a>.</p>
<p><strong>I will have users subscribe by paying</strong>: I suggest take a stroll if this idea is doing the rounds in your head. Do only what you will be comfortable with if you were the user. This could only work if what you are selling is a product or some indispensable service or support. And yeah, don&#8217;t lame it up like this<a href="http://www.consumeraffairs.com/dating_services/classmates.html" target="_blank">[2]</a>.</p>
<p>Those were the myths. On to the facts.</p>
<p><strong>Micropayments</strong>: Good things come in small packages. Very small. Imagine putting in goodies that cost a dollar by the hundred, and now if you have the userbase, this is bound to work. This may not get you to the top of the Forbes list, but will surely be a steady source of revenue.</p>
<p><strong>Merchandising</strong>: You just have to do a count of the number of websites cropping up that claim to get a customised t-shirt to you. I bump into such websites each day, twice. If you have anything else other than pictures to put up on t-shirts or mugs or teddy bears, this could be just the way to leap out of the screen. Although this might be costly, but margins will be high if done in volumes and shipping be within a manageable geographical area.</p>
<p><strong>Revenue-Sharing</strong>: Google shared commission with people if they put up AdSense code within their pages. Microsoft is showering its resellers. The Facebooks/Bebos have to do this. The fancy of social networking websites has long gone and people are still using it because its as much a part of them as their email addresses. They are spending ever increasing amounts of time each day on these websites and are still not that much loyal to not consider switching to another site, a better and rewarding one. Its only a matter of time before most of these users come to know and believe that they are buying your lunch. And after that its another few moments before someone comes up who is willing to share his lunch and pay his users their share. I can&#8217;t tell you how to share your revenue with your users, totally depends on the niche and technology you are working on, but if you don&#8217;t respect the time and effort your users are putting in you might just find some rough times ahead. This is specially true for websites that are solely thriving on user generated content<a href="http://publishing2.com/2007/10/26/the-user-generated-content-myth/" target="_blank">[3]</a>.</p>
<p>And as another observation, selling anonymized trends on your website to your ad partners is not a very creative way to go about earning money. I guess the next step would be to get businesses to users who just want it. Permission Marketing<a href="http://sethgodin.typepad.com/seths_blog/2008/01/permission-mark.html" target="_blank">[4]</a>.</p>
<p>Whatever you do, don&#8217;t start without a revenue model as that speaks of zero business insight on your part, and secondly it is very tough to incorporate a revenue model later in a very much alive site<a href="http://www.alleyinsider.com/2008/2/google_myspace_deal_hurting_us_nws" target="_blank">[5]</a>. The stories that you might be entertained with is how google and youtube and so on started without a revenue model and so on, and are making big money today, well, they started when internet was only a place to check emails<a href="http://www.economist.com/business/displaystory.cfm?story_id=10880936" target="_blank">[6]</a>, not some place where you shop, play, meet people, learn and almost live your life there. They started out of pure geekness and a need to solve the problems the creators were facing. In comparison RockYou did an exhaustive study of the market and came out with widgets which hit right on target and made RockYou worth around 400mn $<a href="http://valleywag.com/369297/morgan-stanley-trying-to-get-400-million-for-rockyou" target="_blank">[7]</a> in under 2 years. Keep looking and you will be convinced more and more of having a revenue model.</p>
<p>Quoted from <a href="http://www.longtail.com/the_long_tail/2008/01/what-does-the-m.html" target="_blank">What does the &#8220;Media Business Model&#8221; mean?</a>[also contains an exhaustive list of all possible monetization methods]:</p>
<blockquote><p><strong>Both media and most online businesses are based on &#8220;software economics&#8221;, where the cost of creating something of value is relatively high but the marginal cost of distributing it to each consumer is very low.</strong></p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=27&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2008/06/26/social-networking-websites-revenue-models/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2008/06/26/social-networking-websites-revenue-models/</feedburner:origLink></item>
		<item>
		<title>Animate this …</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/ncw2SkL4wpE/</link>
		<comments>http://krahulg.wordpress.com/2008/06/20/animate-this/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 08:23:52 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[This Works]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scriptaculous]]></category>
		<category><![CDATA[settimeout]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/?p=24</guid>
		<description><![CDATA[ In a javascript world ruled by prototype and scriptaculous, all visual effects &#38; animations in web pages are effected by them. But DIY still means Do-It-Yourself. Lets waste no time smelling the perfume and cut to the flesh &#8230;
function animateThis(fxargs, fxtp)
{
var fxargsstr = &#8221;, argseparator = &#8221;;
var fxname = fxargs.callee.toString();
fxname = fxname.substr(&#8216;function &#8216;.length);
fxname = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=24&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FJavascript_animations_without_prototype_or_scriptaculous' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe> In a javascript world ruled by prototype and scriptaculous, all visual effects &amp; animations in web pages are effected by them. But DIY still means Do-It-Yourself. Lets waste no time smelling the perfume and cut to the flesh &#8230;</p>
<p><strong>function animateThis(fxargs, fxtp)<br />
{<br />
var fxargsstr = &#8221;, argseparator = &#8221;;<br />
var fxname = fxargs.callee.toString();<br />
fxname = fxname.substr(&#8216;function &#8216;.length);<br />
fxname = fxname.substr(0, fxname.indexOf(&#8216;(&#8216;));<br />
for(var i = 0; i &lt; fxargs.length; i++)<br />
{<br />
fxargsstr = fxargsstr + argseparator + &#8220;&#8216;&#8221; + fxargs[i] + &#8220;&#8216;&#8221;;<br />
argseparator = &#8216;,&#8217;;<br />
}<br />
fnstr = fxname +&#8217;(&#8216;+fxargsstr+&#8217;)';<br />
setTimeout(fnstr, fxtp);<br />
}</strong><br />
What is that?? Hmmm &#8230; I guess I am seeing settimeout on steroids. Put:</p>
<p><strong>animateThis(arguments, &lt;a span of your choice measured in milliseconds&gt;);</strong></p>
<p>in a function body and that function gets called every that many milliseconds with the exact argument set supplied to it as was supplied when the function was first called. So a Fade-In function in javascript using this function would look like this:</p>
<p><strong>function fadeIn(elementID)<br />
{<br />
var el = document.getElementById(elementID);<br />
var opac = el.style.opacity; //read the current opacity value of the target element<br />
if(opac &lt; 1) //if not reached full opacity<br />
{<br />
opac = parseFloat(opac) + 0.05; //increase the current opacity value<br />
el.style.opacity = opac.toString();<br />
animateThis(arguments, 20); //call this function every 20 milliseconds<br />
}<br />
}</strong></p>
<p>and just call this on a div with opacity set as 0 and an ID of lets say &#8216;testdiv&#8217;, with something like:</p>
<p><strong>&lt;a href=&#8217;#&#8217; onclick=&#8221;javascript:fadeIn(&#8216;testdiv&#8217;);&#8221;&gt;bring in&lt;/a&gt;</strong></p>
<p>and see the div come into view. Geekness.</p>
<p>The example will only work on Firefox but the function animateThis() has been <strong>tested on FireFox 2-3, IE 6-7, Safari, Opera</strong>. In case you find some issue, tell me and I will have things set right.</p>
<p>And yeah, CS students, this is not recursion. This is a timer.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=24&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2008/06/20/animate-this/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2008/06/20/animate-this/</feedburner:origLink></item>
		<item>
		<title>Walking the HTML DOM tree in PHP</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/eDHQTB8arNc/</link>
		<comments>http://krahulg.wordpress.com/2007/12/30/walking-the-html-dom-tree-in-php/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 13:44:36 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[Document Object Model]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/2007/12/30/walking-the-html-dom-tree-in-php/</guid>
		<description><![CDATA[ Walking the DOM in JavaScript has been covered well and good. But I couldn&#8217;t find substantial help when it came to walking the DOM tree of HTML files in PHP. It seems all there is to DOM is limited to XML. It would be wonderful if we could keep aside all tags and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=22&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FWalking_the_HTML_DOM_tree_in_PHP' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe> Walking the DOM in JavaScript has been covered well and good. But I couldn&#8217;t find substantial help when it came to walking the DOM tree of HTML files in PHP. It seems all there is to DOM is limited to XML. It would be wonderful if we could keep aside all tags and the related regex mumbo-jumbo to parse tags away, and instead check the values, text contained, IDs of elements, their class names and style rules. The function presented here walks through all the elements presented in a HTML file accessing all the node attributes and node values.</p>
<p>Anyways, being the wonderful thing that DOM is, I cooked up a small little function to walk the tree of an HTML file in PHP and print the output to screen, and boy does it walk. Anyway, less talk and more &#8230;<br />
<font color="#993300">&lt;?php<br />
function walkDom($node, $level = 0)<br />
{<br />
$indent = &#8221;;<br />
for ($i = 0; $i &lt; $level; $i++)<br />
$indent .= &#8216;&amp;nbsp;&amp;nbsp;&#8217;; //prettifying the output<br />
if($node-&gt;nodeType != XML_TEXT_NODE)<br />
{<br />
echo $indent.&#8217;&lt;b&gt;&#8217;.$node-&gt;nodeName.&#8217;&lt;/b&gt;&#8217;;<br />
if( $node-&gt;nodeType == XML_ELEMENT_NODE )<br />
{<br />
$attributes = $node-&gt;attributes; // get all the attributes(eg: id, class &#8230;)<br />
foreach($attributes as $attribute)<br />
{<br />
echo &#8216;, &#8216;.$attribute-&gt;name.&#8217;=&#8217;.$attribute-&gt;value;<br />
// $attribute-&gt;name is usually one of these:<br />
// src, type, rel, link, name, value, href, onclick,<br />
// id, class, style, title<br />
// You can add your custom handlers depending on the Attribute.<br />
}<br />
//if( strlen(trim($node-&gt;childNodes-&gt;item(0)-&gt;nodeValue)) &gt; 0 &amp;&amp; count($cNodes) == 1 )<br />
//echo &#8216;&lt;br&gt;&#8217;.$indent.&#8217;(contains=&#8217;.$node-&gt;childNodes-&gt;item(0)-&gt;nodeValue.&#8217;)'; // do this to print the contents of a node, which maybe the link text, contents of div and so on.<br />
}<br />
echo &#8216;&lt;br&gt;&lt;br&gt;&#8217;;<br />
}<br />
$cNodes = $node-&gt;childNodes;<br />
if (count($cNodes) &gt; 0)<br />
{<br />
$level++ ; // go one level deeper<br />
foreach($cNodes as $cNode)<br />
walkDom($cNode, $level); //so this is recursion my professor kept talkin&#8217; about<br />
$level = $level &#8211; 1; // come a level up, and had to do it this way or else wordpress would take away one dash. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
}<br />
}<br />
?&gt;</font><br />
Is that good?? Because here is how you use it:<br />
<font color="#993300">&lt;?php<br />
$doc = new DOMDocument();<br />
@$doc-&gt;loadHTMLFile(&#8216;http://www.google.com&#8217;);<br />
walkDom($doc);<br />
?&gt;</font><br />
And this prints away the entire DOM of the read in file specified by the URL to loadHTMLFile. More information about the used constants and functions can be found <a href="http://www.php.net/manual/en/ref.dom.php" title="takes you to php.net, opens in a new window" target="_blank"><b>here</b></a>. And believe me, this works.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=22&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2007/12/30/walking-the-html-dom-tree-in-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2007/12/30/walking-the-html-dom-tree-in-php/</feedburner:origLink></item>
		<item>
		<title>Search Friendly URLs or No-Question-Marks-Or-Equals URLs</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/5SRLMVtG_jo/</link>
		<comments>http://krahulg.wordpress.com/2007/12/30/search-friendly-urls-or-no-question-marks-or-equals-urls/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 06:50:06 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[This Works]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[friendly urls]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/2007/12/30/search-friendly-urls-or-no-question-marks-or-equals-urls/</guid>
		<description><![CDATA[
Prettifying the address bar is a last stop in the modern day Internet. It is always this way:
Good: http://www.whatasite.com/dude/djjo/music
Bad: http://www.whatasite.com/user.php?cat=dude&#38;profile=djjo&#38;page=music
The name here is search-friendly urls, although how search friendly they have been, nobody knows[SEO people 'can' tell], but they certainly are friendly to users, among other things. So if your question is &#8220;how to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=21&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fwww.digg.com%2Fprogramming%2FSearch_Friendly_URLs_or_No_Question_Marks_Or_Equals_URLs' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
Prettifying the address bar is a last stop in the modern day Internet. It is always this way:</p>
<p><b>Good</b>: http://www.whatasite.com/dude/djjo/music</p>
<p><b>Bad</b>: http://www.whatasite.com/user.php?cat=dude&amp;profile=djjo&amp;page=music</p>
<p>The name here is search-friendly urls, although how search friendly they have been, nobody knows[SEO people 'can' tell], but they certainly are friendly to users, among other things. So if your question is &#8220;how to make search friendly urls or urls without question marks and full stops&#8221;, here is how I do it.</p>
<p>This article is based on the Apache server platform. If you are running Windows, you might try installing WAMP or XAMPP to get Apache. Once you have this running open up <b>httpd.conf</b> in your pink-n-blue text editor and look for something like this:</p>
<p><b>#LoadModule rewrite_module modules/mod_rewrite.so</b></p>
<p>If you can&#8217;t see the &#8216;#&#8217; prefix to the rest of the line, you are lucky, or else remove the &#8216;#&#8217; from the front[uncommenting the command] and restart Apache.</p>
<p>Once this has been done, to check if you are ready to begin and that mod_rewrite is really active, create a file in your web root directory, lets say test.txt with some text in it. And now over to doing the magic. Locate the .htaccess file in your webroot and again get  your pink-n-yeahyeah editor and add the following lines:</p>
<p><b>RewriteEngine On<br />
RewriteRule ^magic\.txt$ test.txt</b></p>
<p>Now try to get magic.txt in your browser and you will definitely see some magic txt. What you will see is the contents of test.txt, as if you asked for test.txt, which is what you did. Lets explain the above two lines to ourselves. URL Prettifying needs a little bit of knowledge of Regular Expressions. You can <b>learn about regular expressions</b> <b><a href="http://gnosis.cx/publish/programming/regular_expressions.html">here</a></b>, <b><a href="http://www.amk.ca/python/howto/regex/">here</a></b> &amp; <b><a href="http://www.zytrax.com/tech/web/regex.htm">here</a></b>. The first line sets the RewriteEngine rolling and the second line is a rewrite rule. The first part of the rule:</p>
<p><b>^magic\.txt$</b><br />
^ = the beginning<br />
\. = look for the character &#8216;.&#8217;. A plain &#8216;.&#8217; in a regex means any non-whitespace character.<br />
$ = and this is the end</p>
<p>The second part is the name of the file or the new url which is sent to the server instead of the first part. So in our case, asking for &#8216;magic.txt&#8217; will get you test.txt. So basically a RewriteRule is of the form:</p>
<p><b>RewriteRule &lt;what the browser asks&gt; &lt;what you serve&gt;</b></p>
<p>Please note that, all rules should come after the &#8216;<b>RewriteEngine On</b>&#8216; directive, and unless this line is found, not a single rule will be interpreted it. And now for a funnier version, try this rule instead of the earlier one:</p>
<p>RewriteRule ^magic\.txt$ http://www.google.com</p>
<p>So before you get ideas, let me finish what we begun here. Lets say we have a website that generates a URL like this one to go to an album page:</p>
<p>http://www.whatasite.com/album.php?user=djjo&amp;page=7</p>
<p>Now as cumbersome that is to remember, and search engines are known to run for cover on seeing such pages as these dynamic pages are known to be pointing towards itself and doing such round and closed references thus taking an awful lot of time of the search crawler. Bad. We want the crawler to see this, for which we need to make it look like regular html pages with no scary or &#8217;special&#8217; characters:</p>
<p>http://www.whatasite.com/album/djjo/7</p>
<p>And the rule to do the above is:</p>
<p><b>RewriteRule   ^album/([a-z]+)/([0-9]+)$     album.php?user=$1&amp;page=$2</b></p>
<p>Just a gentle reminder, that these rules are to be written in a file named .htaccess lying in your web root(typically named &#8216;www&#8217;) directory. Now onto simplifying the above rule:</p>
<p><b> ^album/([a-z]+)/([0-9]+)$</b></p>
<p>^, from the start match the string &#8216;album&#8217; followed by the first slash</p>
<p>([a-z]+),  after the first slash, look for a group of characters[the characters allowed are from 'a' to 'z' and '+' sign means 'one or more'], which we know to be the user name. A group enclosed in brackets is considered as a variable. <b>Since this is the first group[the username], it will be called $1</b>. We will use this in the second part of the rule.</p>
<p>/([0-9]+)$, and after the second slash, look for another group of numerals from 0 to 9, and one number or more. <b>And as this is the second group[the page number], this is $2</b>. The final $ at the end of the expression means we end the first part here, so its like a terminator.</p>
<p><b>album.php?user=$1&amp;page=$2</b></p>
<p>We have $1[username] &amp; $2[page number] from the first part of our rule. So we will substitute these values to our URL as they earlier were supplied, which make the second part quite easily look like what we have here.<br />
I guess that pretty much does the job here. And oh yeah, if your user name has numerals in it[alongwith alphabets], just use something like this [a-z0-9]+ instead of [a-z]+. A range of <b>uses of url rewriting have been written about <a href="http://httpd.apache.org/docs/1.3/misc/rewriteguide.html">here</a></b>. Should you have any queries or doubts or clarifications to make, just leave a comment and I will be good enough to notice it.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=21&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2007/12/30/search-friendly-urls-or-no-question-marks-or-equals-urls/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2007/12/30/search-friendly-urls-or-no-question-marks-or-equals-urls/</feedburner:origLink></item>
		<item>
		<title>Add content dynamically as you reach end of page with AJAX</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/T4l0kP4zjSo/</link>
		<comments>http://krahulg.wordpress.com/2007/12/27/add-content-dynamically-as-you-reach-end-of-page-with-ajax/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 17:12:16 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[This Works]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[scroll]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/2007/12/27/add-content-dynamically-as-you-reach-end-of-page-with-ajax/</guid>
		<description><![CDATA[
You have a search page and as the results end you show a navigation bar with links to the other pages of the search. So boring. Seriously. This is the Web, and I am still turning pages.
And I think I am Pied Piper who will save you from this hell. The uber-cool solution is, detect [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=18&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fwww.digg.com%2Fprogramming%2FAdd_content_dynamically_as_you_reach_End_of_Page_with_AJAX' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
You have a search page and as the results end you show a navigation bar with links to the other pages of the search. So boring. Seriously. This is the Web, and I am still turning pages.</p>
<p>And I think I am Pied Piper who will save you from this hell. The uber-cool solution is, detect as soon as a user is about to reach the end of the page and get new content[the second page of the search], just in time. Setting out, we need:</p>
<p><b>The height of the current document</b>. So to this end, we will place a div with a decided upon ID at the end of the page. And all the content in the body will be loaded in another div just above this last div. We are detecting the document height by detecting where this ending div is located, pixel-wise, with this:<br />
<font color="#0000ff"><br />
</font><font color="#0000ff">pageend = document.getElementById(&#8216;laststop&#8217;).offsetTop;</font></p>
<p>So clearly, the ID of the last div is &#8216;laststop&#8217;. Next we need the <b>screen resolution of the client window</b> to find out how much of the document is visible right now. We do:</p>
<p><font color="#0000ff">winheight = (typeof window.innerHeight != &#8216;undefined&#8217; ? window.innerHeight : document.body.offsetHeight);</font></p>
<p>Now having this much, we need to detect <b>when does the user scroll the page to the bottom</b>. The following lines will give exactly how many pixels from the top have you scrolled to. Note that, this is the <b>&#8216;height&#8217; from the top of the document to the top of the visible area. The real end of the document is obtained by adding this &#8216;height&#8217; and the window height retrieved earlier.</b></p>
<p><font color="#0000ff">if(navigator.appName == &#8220;Microsoft Internet Explorer&#8221;)<br />
alert(document.body.scrollTop);<br />
else<br />
alert(window.pageYOffset);</font></p>
<p>But these lines need to be run every few seconds to check as soon as as the user reaches the end of the current page. So we will do a setInterval() in the onload event of the body to do so. And keep the interval time to something a little over 2 seconds and nothing less than that, you of course don&#8217;t want your user&#8217;s browser to hang on them. It is annoying.</p>
<p>Said and done, this is what you end up with, <b>demofile.php</b>, annotated with explanatory comments:</p>
<p><font color="#0000ff">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Page End Reached Detection Demo&lt;/title&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var oRequest;<br />
var pageend, winheight;<br />
var howoften = 2000;<br />
// this value implies that function howlow() will keep checking every<br />
// 2000 milliseconds(2 seconds) to find out how low is the user on the page</font></p>
<p><font color="#0000ff">var bufferHeight = 300;<br />
// adjust bufferHeight, to take action as soon as the user is within these<br />
// many pixels of the end of the page, so a larger buffer makes sure the user doesn&#8217;t<br />
// see the dynamic page content loading. In this example, the script will fetch content<br />
// as soon as you are within 200 pixels of the end of the page</font></p>
<p><font color="#0000ff">// ooooo, ajax. ooooooo &#8230;<br />
if(window.XMLHttpRequest)<br />
oRequest = new XMLHttpRequest();<br />
else if(window.ActiveXObject)<br />
oRequest = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);</font></p>
<p><font color="#0000ff">function sendAReq()<br />
// a generic function to send away any data to the server<br />
// specifically &#8216;morecontent.php&#8217; in this case, to get more content from the server<br />
// all content fetched will be handled by showcontent()<br />
{<br />
oRequest.open(&#8220;POST&#8221;, &#8220;morecontent.php&#8221;, true);<br />
oRequest.setRequestHeader(&#8220;Content-Type&#8221;, &#8220;application/x-www-form-urlencoded&#8221;);<br />
oRequest.onreadystatechange = showcontent;<br />
oRequest.send(null);<br />
}</font></p>
<p><font color="#0000ff">function showcontent()<br />
{<br />
if(oRequest.readyState == 4)<br />
{<br />
// now all the data that comes adds to the end of the page, specifically<br />
// to the container div referenced with the ID &#8216;bodycontent&#8217;<br />
if(oRequest.status == 200)<br />
document.getElementById(&#8216;bodycontent&#8217;).innerHTML = document.getElementById(&#8216;bodycontent&#8217;).innerHTML + oRequest.responseText;<br />
else<br />
alert(&#8216;No Response from Server. Try Again Later.&#8217;);<br />
}<br />
}</font></p>
<p><font color="#0000ff">function calcParams()<br />
{<br />
// calculate the end coordinates of the page and the visibile height of a page<br />
// at any time on the client&#8217;s desktop<br />
pageend = document.getElementById(&#8216;laststop&#8217;).offsetTop;<br />
winheight = (typeof window.innerHeight != &#8216;undefined&#8217; ? window.innerHeight : document.body.offsetHeight);<br />
}</font></p>
<p><font color="#0000ff">function isitend(curpos)<br />
{<br />
calcParams();<br />
if((curpos + winheight + bufferHeight) &gt; pageend)<br />
{<br />
alert(&#8216;you are reaching the end of the page;&#8217;);<br />
sendAReq();<br />
}<br />
else<br />
{<br />
alert(&#8216;keep going&#8217;);<br />
}<br />
}</font></p>
<p><font color="#0000ff">function howlow()<br />
{<br />
if(navigator.appName == &#8220;Microsoft Internet Explorer&#8221;)<br />
isitend(document.body.scrollTop);<br />
else<br />
isitend(window.pageYOffset);<br />
}<br />
&lt;/script&gt;<br />
&lt;/head&gt;</font></p>
<p><font color="#0000ff">&lt;body onload=&#8221;javascript:setInterval(&#8216;howlow()&#8217;,howoften);&#8221;&gt;<br />
&lt;div id=&#8217;bodycontent&#8217;&gt;<br />
&lt;?php<br />
for($index=0; $index&lt;200; $index++)<br />
echo &#8216;Line:&#8217;.$index.&#8217;&lt;br&gt;&#8217;;<br />
?&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8217;laststop&#8217;/&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</font></p>
<p>Oh and yeah, this sends a request using the XMLHttp object so we need another php file at the server to catch the request and send in additional content. This additional content will be appended to the div with ID &#8216;bodycontent&#8217;. So here is <b>morecontent.php</b></p>
<p><font color="#993300">&lt;?php<br />
for($index = 0; $index &lt; 100; $index++)<br />
echo &#8216;We Are New Lines:&#8217;.$index.&#8217;&lt;br&gt;&#8217;;<br />
?&gt;</font></p>
<p>That&#8217;s about it. Please do throw in your experiences with this in the comments section below and I will surely respond. I am jobless. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=18&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2007/12/27/add-content-dynamically-as-you-reach-end-of-page-with-ajax/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2007/12/27/add-content-dynamically-as-you-reach-end-of-page-with-ajax/</feedburner:origLink></item>
		<item>
		<title>Preparing a secure login form with PHP &amp; JavaScript</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/H17rUe44cEc/</link>
		<comments>http://krahulg.wordpress.com/2007/12/26/preparing-a-secure-login-form-with-php-javascript/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 21:00:30 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[This Works]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sniff]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/2007/12/26/preparing-a-secure-login-form-with-php-javascript/</guid>
		<description><![CDATA[
We have had encryption, we have had SSLs, &#8230; well we also had digitally signed certificates, but where&#8217;s the hack?? How can you cook up a secure login form that does the following:
[1] doesn&#8217;t send the login information in clear-text
[2] in case somebody is sniffing the line, he/she shouldn&#8217;t be able to login with the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=17&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fwww.digg.com%2Fprogramming%2FPreparing_a_secure_login_form_with_PHP_JavaScript' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
We have had encryption, we have had SSLs, &#8230; well we also had digitally signed certificates, but where&#8217;s the hack?? How can you cook up a secure login form that does the following:</p>
<p><b>[1] doesn&#8217;t send the login information in clear-text</b></p>
<p><b>[2] in case somebody is sniffing the line, he/she shouldn&#8217;t be able to login with the sniffed information</b></p>
<p>So, with the above information in hand, here is what we do, and how we do.</p>
<p>You need:</p>
<p>[1] http://www.webtoolkit.info/javascript-md5.html [<b>javascript implementation of MD5</b>]</p>
<p>[2] Two php functions. <b>runquery($query) , which will run a query</b> supplied as string &amp; <b>getcol($query) will get the column asked for</b> in a select statement.</p>
<p>Now, create a table, if you don&#8217;t already have, to store user information. What we do want to be stored is the login timestamp.</p>
<p>create table user(<br />
loginid varchar(200),<br />
password varchar(200),<br />
lastLoginTS bigint<br />
);</p>
<p>Now your <b>login.php</b> file should look like this:</p>
<p><font color="#0000ff">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Secure Login Form&lt;/title&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;md5.js&#8221;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;form action=&#8221;dologin.php&#8221; method=&#8221;post&#8221; onsubmit=&#8221;javascript:document.getElementById(&#8216;phash&#8217;).value = MD5(document.getElementById(&#8216;password&#8217;).value + document.getElementById(&#8216;hts&#8217;).value);  document.getElementById(&#8216;password&#8217;).value = &#8221; ;&#8221;&gt;<br />
LoginID: &lt;input type=&#8221;text&#8221; name=&#8221;loginid&#8221;&gt;&lt;br&gt;<br />
Password: &lt;input type=&#8221;password&#8221; name=&#8221;password&#8221; id=&#8221;password&#8221;&gt;&lt;br&gt;<br />
&lt;?php<br />
$TS = time(); //the current timestamp<br />
echo &#8220;&lt;input type=&#8217;hidden&#8217; value=&#8217;&#8221;.$TS.&#8221;&#8216; name=&#8217;hts&#8217; id=&#8217;hts&#8217;&gt;&lt;br&gt;&#8221;;<br />
?&gt;<br />
&lt;input type=&#8217;hidden&#8217; name=&#8217;phash&#8217; id=&#8217;phash&#8217; value=&#8221;&gt;<br />
&lt;input type=&#8221;submit&#8221; value=&#8221;send&#8221;&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt; </font></p>
<p><font color="#000000">This file assumes in the line &#8220;&lt;script type=&#8221;text/javascript&#8221; src=&#8221;md5.js&#8221;&gt;&lt;/script&gt;&#8221;</font> that <b>you have a file named md5.js in the same directory as login.php, and the javascript file should have a function named MD5()</b>. So make sure this is the case. Next up is <b>dologin.php</b>:</p>
<p><font color="#993300">&lt;?php</font></p>
<p><font color="#993300">$loginid = $_REQUEST['loginid'];<br />
$phash = $_REQUEST['phash'];<br />
$hts = $_REQUEST['hts'];<br />
$password = getcolumn(&#8220;select password from user where loginid=&#8217;$loginid&#8217;;&#8221;);<br />
$lastLoginTS = getcolumn(&#8220;select lastLoginTS from user where loginid=&#8217;$loginid&#8217;;&#8221;);</font></p>
<p><font color="#993300">if(strlen($loginid) &gt; 0 &amp;&amp; strlen($phash) &gt; 0 &amp;&amp; $phash == md5($password.$hts) &amp;&amp; $hts &gt; $lastLoginTS)<br />
{<br />
runquery(&#8220;update user set lastLoginTS=&#8217;&#8221;.time().&#8221;&#8216; where loginid=&#8217;$loginid&#8217;;&#8221;);<br />
echo &#8220;done&#8221;;<br />
}<br />
else<br />
echo &#8220;failed&#8221;;<br />
?&gt;<br />
</font></p>
<p>That&#8217;s it. So now what is the deal here. This is your regular login form except that the password is hashed with a timestamp value sent in a hidden form field named &#8216;hts&#8217;. The hashing is done in the event handler for the Javascript onsubmit event, and the password field is cleared as well, to prevent it from being sent in the clear.</p>
<p>The server receives the loginid, timestamp and the hashed value from the client. Retrieve from your database the original password for the loginid specified and calculate another hash at the server with the help of the retrieved original password and the timestamp sent by the client. If the user typed the password correctly, the hashes will match.</p>
<p>This method of course, sort of, encrypts the password and hence prevents the password from being sent in clear, should anybody be sniffing the lines. But should anybody be really sniffing the lines, he/she can just store the values and send them again and again to validate him/herself at the server posing as the valid user. To prevent that, there is another check at the server just before validating. The timestamp sent by the client should be always greater than the last login timestamp stored in the database for that user. Since the last login timestamp is only updated on a successful login, as soon as a valid user logs in, the last login timestamp for the user is updated in the database, and as a result, the sniffed information is rendered stale. The hash now needs to be calculated again using a fresh timestamp and a password which only the user and server know.</p>
<p>I hope this suffices for most of you out there.</p>
<p><b>UPDATE</b> : <font color="#800000"><b>This is a proof of concept</b>.</font> The system described here lacks certain things which are very obvious and shouldn&#8217;t omit them just because I haven&#8217;t mentioned them here to make it simple to grasp. Foremost[thanks William], don&#8217;t store passwords in cleartext on the server. Try looking up &#8220;hashing password with salts&#8221; for that.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=17&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2007/12/26/preparing-a-secure-login-form-with-php-javascript/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2007/12/26/preparing-a-secure-login-form-with-php-javascript/</feedburner:origLink></item>
		<item>
		<title>How long do your users stay on a page??</title>
		<link>http://feedproxy.google.com/~r/Observances/~3/UtcS2nkAMSw/</link>
		<comments>http://krahulg.wordpress.com/2007/12/25/how-long-do-your-users-spend-on-a-page/#comments</comments>
		<pubDate>Tue, 25 Dec 2007 13:00:20 +0000</pubDate>
		<dc:creator>krahulg</dc:creator>
				<category><![CDATA[Experiment]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[page optimization]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://krahulg.wordpress.com/2007/12/25/how-long-do-your-users-spend-on-a-page/</guid>
		<description><![CDATA[
So &#8230; here&#8217;s the real deal into measuring how much time a user spends on each individual page by url, and measured in milliseconds.
[1] As soon as page loads, set the current time in a variable in javascript with the help of the onload event. Let this variable be called tstart.
[2] On the unload event, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=9&subd=krahulg&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fwww.digg.com%2Fprogramming%2FHow_long_do_your_users_spend_on_a_page' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
So &#8230; here&#8217;s the real deal into measuring how much time a user spends on each individual page by url, and measured in milliseconds.</p>
<p>[1] As soon as page loads, set the current time in a variable in javascript with the help of the onload event. Let this variable be called tstart.</p>
<p>[2] On the unload event, get the current timestamp, and subtract from this the starting timestamp, the first one. So tTotal = tend &#8211; tstart.</p>
<p>[3] Now send this time information alongwith location.href to your server, which will record this in a log file, or database to use later, maybe to serve relevant content by keeping in mind a users viewing and browsing patterns.You get the picture right.</p>
<p>So here  are the files. Just store <span style="color:#0000ff;"><strong>monitorme.html</strong></span> &amp; <span style="color:#0000ff;"><strong>logtimefile.php</strong></span> somewhere on your server and create a writeable file in the same directory named as<strong><span style="color:#0000ff;"> timelog.txt</span></strong>. Now get monitorme.html and now refresh your page, navigate away to some other page or just plain close the window to find your timelog.txt file piling up with times you spent on the page.</p>
<p><strong> monitorme.html</strong></p>
<p><span style="color:#0000ff;"> &lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Duration Logging Demo&lt;/title&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var oRequest;<br />
var tstart = new Date();</span></p>
<p><span style="color:#0000ff;">// ooooo, ajax. ooooooo &#8230;<br />
if(window.XMLHttpRequest)<br />
oRequest = new XMLHttpRequest();<br />
else if(window.ActiveXObject)<br />
oRequest = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);</span></p>
<p><span style="color:#0000ff;">function sendAReq(sendStr)<br />
// a generic function to send away any data to the server<br />
// specifically &#8216;logtimefile.php&#8217; in this case<br />
{<br />
oRequest.open(&#8220;POST&#8221;, &#8220;logtimefile.php&#8221;, true); //this is where the stuff is going<br />
oRequest.setRequestHeader(&#8220;Content-Type&#8221;, &#8220;application/x-www-form-urlencoded&#8221;);<br />
oRequest.send(sendStr);<br />
}</span></p>
<p><span style="color:#0000ff;">function calcTime()<br />
{<br />
var tend = new Date();<br />
var totTime = (tend.getTime() &#8211; tstart.getTime())/1000;<br />
msg = &#8220;[URL:"   location.href   "] Time Spent: &#8221;   totTime  &#8221; seconds&#8221;;<br />
sendAReq(&#8216;tmsg=&#8217; msg);<br />
}<br />
&lt;/script&gt;<br />
&lt;/head&gt;</span></p>
<p><span style="color:#0000ff;">&lt;body onbeforeunload=&#8221;javascript:calcTime();&#8221;&gt;<br />
Hi, navigate away from this page or Refresh this page to find the time you spent seeing<br />
this page in a log file in the server.<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</span></p>
<p><strong> logtimefile.php</strong></p>
<p><span style="color:#993300;">&lt;?php<br />
function logtimemsg($timemsg)<br />
{<br />
//write your own handling code here, store it in a file or store it in a DB, whatever<br />
$logfilename = &#8216;timelog.txt&#8217;;<br />
if (is_writable($logfilename))<br />
{<br />
if (!$handle = fopen($logfilename, &#8216;a&#8217;))<br />
{<br />
exit;<br />
}<br />
if (fwrite($handle, $timemsg.&#8221;\r\n&#8221;) === FALSE)<br />
{<br />
exit;<br />
}<br />
fclose($handle);<br />
}<br />
}</span></p>
<p><span style="color:#993300;">logtimemsg($_REQUEST['tmsg']);<br />
?&gt;</span></p>
<p><strong>UPDATE:</strong> People, I love if anyone of you writes back, even if to tell that this doesn&#8217;t work. Thanks to JayVee who pointed that &lt;body onunload=&#8221;&gt; sucks compared to &lt;body onbeforeunload=&#8221;&gt; for this post. Change accomodated.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/krahulg.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/krahulg.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krahulg.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krahulg.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krahulg.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krahulg.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krahulg.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krahulg.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krahulg.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krahulg.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krahulg.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krahulg.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krahulg.wordpress.com&blog=1238422&post=9&subd=krahulg&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://krahulg.wordpress.com/2007/12/25/how-long-do-your-users-spend-on-a-page/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59a9f13b424b8d6f37c00fd978b42804?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">krahulg</media:title>
		</media:content>
	<feedburner:origLink>http://krahulg.wordpress.com/2007/12/25/how-long-do-your-users-spend-on-a-page/</feedburner:origLink></item>
	</channel>
</rss>
