Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.


AHAH(Asynchronous HTML over HTTP) - AJAX 2.0

AHAH or Asynchronous HTML over HTTP is a much simpler version of AJAX. Using AHAH approach in JavaScript you can display external XHTML pages inside your HTML page. The beauty of the script is that it is so very simple - the underling code is just twenty lines!

The difference between AJAX and AHAH is about XML. AJAX will load an XML file - then the developer will have to make the code that will parse the XML, extract the data and then display the results. In AHAH the approach is much simpler - the data to be fetched is XHTML - the code just has to fetch it - as the browser is already equipped to handle HTML and will display the result with no further help from the developer.

For example, lets say we need to create a page with tabs - each tab will put some content in the main area - but the full thing must be dynamic - linking to another page won't do. The code of the main page will be...

<ul id="tabs">
 <li><a href="load('javascript.html');">JavaScript</a></li>
 <li><a href="load('ahah.html');">AHAH</a></li>
 <li><a href="load('ajax.html');">AJAX</a></li>

<div id="content"></div>

The point of our exercise will be to load the contents of the javascript.html in to the div with the id 'content'. In the JavaScript section of the file we will declare the 'load' function...

<script language="javascript" type="text/javascript" src="ahah.js"></scirpt>
<script language="javascript" type="text/javascript">
//Calls the library function 'ahah' - defined in 'ahah.js' file.
function load(filename) {

The code of the ahah.js file as given below...

function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};"GET", url, true);

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;

Now the only file left is the three content files - javascript.html, ahah.html and ajax.html. The important thing to remember about this is that you should not include the standard HTML stuff like <html><body> etc. in this page - just the content with all the HTML formatting - I am just providing the code for just the file javascript.html here - remember that this is the whole file - nothing other than the shown data must be in that file.


<p><b><u>JavaScript</u></b> is Netscape's cross-platform, object-based scripting 
language for client and server applications. It has dominated the world of internet scripting languages 
for a long time now. With the arrival of new programming methods like <a class="tooltip" 
title="AJAX : Asynchronous JavaScript and XML" href="">AJAX</a>, 
it is much more popular now than ever before.</p>

<p>See the wikipedia article on <a  href="">JavaScript</a>
 for more info on this language.</p>

Use you imagination to create the other two files. Now open the page on a browser to see the magic. See the live example...

More Links

Filed Under...

Categories :
Technorati Tags:

Digg - A News Filtering Service

I recently found this site - I have no idea why it took me so long to find it as I find these kind of sites much sooner. The site I am talking about is Digg a news filtering site similar to Slashdot. The main difference is that when /. is controlled by the main editors, digg is a set of links that the visitors have voted for. I have already found some cool sites with this service.

Digg have a huge number of visitors now - it had been featured in two wired articles. The number of visitors digg has is so big that if a site appears in it main page, the server of the linked site will crumble within a few hours if it can't handle the load. Those who are familiar with Slashdot will recognize this as the infamous Slashdot effect. When digg does this, it is called diggdot effect.

The only complainant I have about this site is about its RSS Feed. I would have expected it to have a feed like has. I subscribe the feed on my Firefox browser - I have a dropdown on my bookmark toolbar by creating a live bookmark of feed. Every item when clicked will take me to the url of the item. But in the case of Digg's rss feed it is not like that. In digg, every item when clicked will take me to a section of the digg site with a little info about the item. I have to click on a link there to take me to the item's URL.

Filed Under...

Categories : Technorati Tags:

Project Completed

I have handed over my PHP project report that I did as the final year project for BCA in IGNOU. It is a Content Management System in PHP. It is perhaps the only CMS in PHP that does not use MySQL to store the data. The system completely relays on the File System of the hosting computer to store the data. I have not released the code - as it is not yet stable. I had to turn in the code at this point because the deadline had been reached.

We had to create a fifty page project report to go with the code. And I was having trouble reaching twenty pages - at which point I knew that I had to do something drastic. That is when this gem dripped from my pen.

Upon receiving a request from a web browser, the server which host the CMS software will send the requested file(s) directly to the user's browser. The browser will then parse the provided HTML code and will try to resolve all the embedded image, formatting and scripting information in the HTML file and will display the web page on the user's screen.

Know what it says? Basically it says that the link user clicks on will be opened. After that I had no trouble reaching the required fifty - in-fact I overshot it by a good twenty more. I have trouble understanding what it said even thought I wrote it. I can read perl scripts I wrote 2 years ago more easily. I think I have a good future at writing EULAs.

Filed Under... Categories : Technorati Tags:

MD5 is Dead - use SHA1

MD5 has been on its last legs for some time - now it is 'offically' dead. A C program has been released that can find the collitions of a given MD5 Hash within just 45 minutes on a decent computer. MD5 has been proven to be a weak algorithm for some time now - infact, it had been banned from microsoft in support of better algorithms like SHA.

If you are building a new application, think twice before using MD5 to encrypt the passwords - use SHA instead. PHP has a function sha1() that can be used to find the hash of any string. Example...

$encrypted_password = sha1($_POST['pass']);

MySQL also has a SHA function - you can use it like

mysql> SELECT SHA1("abc");
    -> 'a9993e364706816aba3e25717850c26c9cd0d89d'

# OR from PHP as 

mysql_query("INSERT INTO users(login,password) 
VALUES('" . addslashes($_POST['username']) . "', SHA1('" . addslashes($_POST['password']) . "')");

# OR as

$sql_handle = mysql_query("SELECT user_id FROM users 
WHERE user_login='".addslashes($_POST['username'])."' 
AND user_password=SHA1('".addslashes($_POST['password'])."')");

If you want to find the password that was encrypted using MD5, you are better of using the Online Hash Database. This is a database having a huge number of MD5 Hashes and its plain text counterparts. So if you input a MD5 hash, it will search its database to find which text has the given MD5 hash. This system will be defeated if you use a salt when creating the hash.

Filed Under...
Categories :
Technorati Tags:

1000% Increase in Googe AdSense Clicks

No it is not a typo - 1000% increase in Googe AdSense clicks - I did not mean 100%, I meant 1000% increase. I was averaging at around, say, X clicks per day - that is till 12th of this month. Suddenly the number of clicks jumbed to 3X - and the next day to 7X. Next day it was 10.5X. The last time I checked it was 10X. (Sorry about the X thing - but Google won't let me print the exact numbers - atleast I think that they will not let me - who can understand EULAs?) By now you will be wondering what I did and would be itching to try the trick on your own site. I did very little - just changed the location of an ad in one page.

My Online Sudoku page was reciving around 600 page impressions per day - and it was giving me a fair amount of clicks. But then I noticed that left area of that page was wasted - only white space there. So I changed the location of the AdSense Ads to that space instead of the default right side of the page as in other pages. As a result, the amount of AdSense clicks on the page skyrocketed. And this is just from one page - I can't wait to see what will happen when I implement this on other pages.

If you are a AdSense publisher, try out this experiment. Choose a page that recives a good amount of page impressions per day - somewhere above 100. Now create a custom url based channel for that page in AdSense report section(If you don't know how to make a channel, see AdSense Support about this topic). Then change the Ad layout, position and color of the ads. Use one layout for one full day. Then use another for the next day. You will find that some layout will pay much more than others. You will have to experiment to find which one is the best for you. There is no 'one-size-fits-all' formula for this. When you find that 'perfect' ad placement, try it out on the other pages. Before long you will be earing much more than before.

For more information about which placements might be the best, check out the heat map provided by google. Also see this report entitled What We Saw When We Looked Through Their Eyes.

There is no way to say with authority which colours are the best once. Some people say that they get better results when they make the ads stand out of the page. Other say that results are better when they blend the ads with the colours of the page. The only solution to this problem is to experiment on your site by changeing colors of the ads till a clear winner emerges.

If you are a web site owner but not a Google AdSense publisher - what in the world are you waiting for? Get Google AdSense in your site - it won't cost you a thing(yes, you heard me - joining you for the program is free). And if you pay a little attension to your site, it will pay you a lot.

If you have tried the experiment, please use the comment section and let me know which method(s) worked for you. Or if you have some tips that were not said here(there are lots of them), share it with us.

Filed Under Categories : Technorati Tags:

Google Analytics

Google just released a new product - Google Analytics. It is not a new product per se - AdWords publishers had access to this tool earlier - but now it is released to the common public. This is a site that will analyze traffic to a site and display it to the user in a graphical and friendly way.

I have used many traffic logging sites in the past for my website Bin-Co. This softwares include StatCounter, eXtream Tracker, SiteMeter etc. But being free softwares, they had their restrictions - for example, StatCounter will log the details of only the last ten visitors. eXtream Tracker don't log nearly as much information about the visitors as StatCounter does. They all have their own benefits and their own disadvantages.

Now that Google have stepped into the field, things will start to change. The only restriction I have heard about their software is that they allow only sites will less than five million hits per month - and that is still a long way for my site.

You have to register an account with Google to use this service - any Google account will do - gmail, Google sitemaps, Google group etc. accounts will do fine. Next you have to define your site - it is a little tricky here - only top level domains will be accepted - I can't enter my site - but had no problems when entering my Blog at Next you will have to enter a few personal details like name, etc. Then you will be given a small javascript snippet that you will have to enter into your site. After this you can see your website stats at the Google site. I have just entered the code to my Blogger template - I can't wait to try this out. Hope you will feel the same.

But even now the best way to analyse your traffic is referral logs created by your server. Lets see if Google can beat that with its latest offering.

Related Links...
Google Analytics Features
News of release
Other's Perspective
Slashdot Discussion of this feature.

Filed Under...
Categories :
Technorati Tags:

Advice on Paypal

I want some advice from my fellow paypal users. I am trying to buy a domain name from They accept Paypal so I never thought that there will be a problem as I have some money in my paypal account that could be used to buy the domain. But when I tried to buy it, I found that I could not make the purchase - I think that it may have something to do with that I am not a verified user. And for being a verified user, I have to connect a credit card to that account.

This is a big problem for me - as I can't get a Credit card. I could easy get one - but not one that can do transactions in US dollars. I applied for one of those - and I just heard that my application was rejected. So I am hoping that some one could tell me how to make a transaction thru paypal account even if it is unverified. Is it possible? If yes, how? Just leave a comment here - I will get it. Thanks for your time.

Technorati Tags: Tags :

Problem with the new design

The new design has a few troubles - and the biggest one is that I don't know what its troubles are. A CSS file working perfectly in my system will have severe issues when it is uploaded to the net. An element that appears perfectly in Internet Explorer will appear very much out of place in Firefox. The perfectly aligned page in 1024x768 resolution will adjust itself to resemble something the cat brought in when it the page is open in 800x600 resolution.

Anyway, it is still a work in progress - I have to republished the entire site - the older posts are still in the old format. Just let me know if you notice any trouble in the browser you are using. I will try to solve it - although I can't make any promises.

Filed Under...
Categories :
Technorati Tags:

New Blog Design

Finally - implemented the three column layout for the blog. This design is totally mine - the last design was ripped off from inspired by Google Blog. I did this in pure CSS - no tables were used for the layout. Table was used to create the calendar - but that is tabular data so the usage of table in that area is justified.

I have tested the layout in Windows using IE and Firefox - worked well in 1024x768 resolution. The design will hold when it is taken to 800x600 resolution but will break when the window is resized to an even lower width. Now I will have to test it in other systems. If you see any problems just leave a note and I will see what I can do about it.

It was fun creating a CSS layout. Although I have done it before, they were for theoretical purposes - this is the first time I am creating a CSS layout for a real site. Some problems that appeared were expected - while others were a complete surprise. I hate to admit this but tables are a much easier way to design a site. The only problem now is the total lack of colours in the layout - just white and back and something in between.

Filed Under Categories : Technorati Tags:

getElementsByClassName() Function for JavaScript

A very needed function for javascript - the getElementsByClassName(). Many versions of this function are floating around the net - and each with a different but similler name. Like document.getElementsByClass or getElementByClass or getElementByClassName etc. And as if that was not enough, I made one of my own. Call it like this - var anchors = getElementsByClassName("external","a");. This will return all the anchors that are in the 'external' class. Or use just var anchors = getElementsByClassName("external"); this will return all elements that are in the 'external' class.

//Get all the elements of the given classname of the given tag.
function getElementsByClassName(classname,tag) {
 if(!tag) tag = "*";
 var anchs =  document.getElementsByTagName(tag);
 var total_anchs = anchs.length;
 var regexp = new RegExp('\\b' + classname + '\\b');
 var class_items = new Array()
 for(var i=0;i<total_anchs;i++) { //Go thru all the links seaching for the class name
  var this_item = anchs[i];
  if(regexp.test(this_item.className)) {
 return class_items;
Filed Under.. Categories : Technorati Tags:

'Links to this post' Option for Blogger

Google Blog has an intresting new feature - 'Links to this post' - Blogger has activated this feature for all its sites. This will show all the links from everywhere to that particualar post. This is not the ping or trackback feature that Wordpress or Moveable Type or other such blogging softwares - this system will search the web in real time for all the links to that particual post - kinda like what technorati does. I should have seen this comming when google decided to create a Blog Search

The template of Google Blog was updated - even the first post have the 'Links to this Post' option. Now the big question - do I use this option in my blog? Maybe - I am not sure - I have to wait for others to try it out first before trying it out myself. Why be the gunie pig when you can get others to do it for you? But if it works out fine, the trackback feature of other major blogging platforms like Moveable Type and WordPress will be obselete.

Filed Under
Categories :
Technorati Tags:

Subscribe to : Posts