Getting visitor location in PHP.

I had been trying to track the location of visitors based on their IP addresses. I ran into problems earlier while trying to acheive that and gave up. Today, I Finally managed to do that. Thanks to the geodb availablehere. I hacked up a function that would accept an IP address as a parameter and return an array with location info.

The code for the function is:

function getIpInfo($ip){
$ipa=explode(".",$ip);
$ipnum=256*256*256*$ipa[0]+256*256*$ipa[1]+256*$ipa[2]+$ipa[3];
 //download the Geo DB file from http://software77.net/geoip-software.htm
$handle = fopen("IpToCountry.txt", "r");
$userinfo=NULL;
while (!feof($handle)){
 list ($start, $finish, $a1,$a2,$a3,$a4,$a5) = explode("\t",fgets($handle));
   if(($start<=$ipnum)&&($ipnum<=$finish)) {$userinfo=array($a3,$a4,$a5); break; }
}
fclose($handle);
if(!$userinfo) $userinfo=array('Cannot Trace the Ip address','Cannot Trace the Ip address','Cannot Trace the Ip address');
return $userinfo;
}

One just needs to change the name of the file (in my case ‘IpToCountry.txt’) to the one that they have downloaded.The array returns (’2 Digit Country Code’, ‘3 Digit Country Code’, ‘Full Country Name’), and, you can use it to display location or use it in your script as a variable. Make sure you do ip validation befor passing the IP address (ip2long()). A demo of it is available here. For a list of Other PHP/Javascript Demos please go to here.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • YahooMyWeb
  • Furl
  • Netscape
  • Fark
  • StumbleUpon
  • De.lirio.us
  • IndiaGram
  • IndianPad
  • Simpy
  • SphereIt

news.ycombinator search

I am a regular reader of news.yc and like most people using that site, I wanted to be able to search the site. Since the site does not have an inbuilt search functionality, I created yc.news search here.

Just like in SansJ, one can use the search plugin (FF and IE7 only) and search from their browsers search bar. Also, existing users of SansJ will be able to login with their current SansJ usernames and passsword.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • YahooMyWeb
  • Furl
  • Netscape
  • Fark
  • StumbleUpon
  • De.lirio.us
  • IndiaGram
  • IndianPad
  • Simpy
  • SphereIt

Scriptaculous Draggable in Action.

(If you are in a hurry, go here, that is what the post is about.)

It’s finally over!!

Relief followed by pride-both preceded by an Idea- pretty much summarizes my feeling now.

Recently I got a HTC Touch for my dad, which, I played around with for a while.I somehow feel, that, the Input devices (Mouse and Keyboard) that I use majority of the time is less fun than using a Touch Sensitive Interface. Maybe fun is not the right word, but, nevertheless the feeling is fun as you move your fingers across the Screen.

I have read in many places that the Market for Mobile Phones is increasing at a rapid rate and hence, I infer that the market for applications designed for such phones should be growing as well. The point is I would like to develop apps that are at the cutting/leading edge for mobile handsets. But, the problem as I see it is the size, yes, the size of the Screens, until we have some sort of a low-cost foldable-screen introduced in the market, I will stick with PC’s.

This is where Scriptaculous Draggables, caught my attention. The way one could drag an element (divs, tables, etc..) on the screen is cool and yes, it is fun.I had been working on an idea for a few weeks and when I hit a bump, I left the code alone for a week and came back to it yesterday. At the end of it all, I learned a few things in Javascript and CSS. I am hoping that this knowledge and showcase would be implemented in one of my other Projects:SansJ.

Anyway, checkout the Demo here: http://play.trk7.com/drag.html

I used a few Icons from the very nice Sweetie Icon Set available here: http://sweetie.sublink.ca/

and if you wish to look at my demos, you can go here: http://play.trk7.com (just one Demo is linked at the moment, I am planning on a regular update.)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • YahooMyWeb
  • Furl
  • Netscape
  • Fark
  • StumbleUpon
  • De.lirio.us
  • IndiaGram
  • IndianPad
  • Simpy
  • SphereIt

Online Spell Checker…

This can be viewed online on my Social Search site Sansj.com. try searching for Yahoi Search.
It is a good thing have a spell checker facility in a Search Engine, people are not always correct with their spelling and yeah sometimes typos do occur. I read somewhere about using a statistical model to develop a spell checker, and, I was amazed. But I had neither the time or the brain to implement/optimize it,so I went for the easier option, I used yahho spell checker api available here.The code I came up with (with some help from my previous work and also a few other work available on the internet) is presented here:

//COPY PASTING WILL NOT WORK, UNLESS, YOU ARE WILLING TO CHANGE THE QUOTES
$req_spcheck=’http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=YOURIDGOESHERE&query=YOURQUERY&results=3&output=php’; ///create the query here, output is serialized PHP
$checked=”;
$res = file_get_contents($req_spcheck);
$phpobj_spcheck = unserialize($res);
$key2=0;
foreach($phpobj_spcheck as $arr2) { ///for each loop to get each of the suggestions
$key2++;
$checked.=’<a href=”http://trk7.com/ask/mysearch2.php?sstring=’.trim(urlencode($arr2[’Result’])).’&submit=&co=all”>’.($arr2[’Result’]).’</a>’; ///create a link that can be used also as a search query on my site
$str4=$arr2[’Result’];
}
if ($str4!=”"){ //making sure we r getting a corrected result
echo “<div style=’font-size:1.2em;background-color:#FFFFCC;border-top:1px solid gold;border-bottom:2px solid gold;text-align:left’><img src=’images/spellcheck.png’ style=’padding-right:2px’ alt=’Spellitrite ‘ />Did you mean:”.$checked.”?</div>”; ///display the spell suggestions
}

This can be viewed online on my Social Search site Sansj.com. try searching for Yahoi Search.

Totally Cool.
P.S. Should have known that, to display code in wordress, should have used htmlentities.Thanks.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • YahooMyWeb
  • Furl
  • Netscape
  • Fark
  • StumbleUpon
  • De.lirio.us
  • IndiaGram
  • IndianPad
  • Simpy
  • SphereIt

SansJ.com updates.

My Social Search Engine:SansJ has had some updates to it’s interface recently. Most notable is the use of CSS based Buttons instead of standard HTML buttons. Thanks to some excellent free web 2.0-ish icons available here, I have been able to create some good-looking CSS buttons.The new menubar at the top has been created with help from here; which is a wonderful site to learn about HTML <li> and also look at some implementations (mainly CSS based menus).

I wa surprised to find that IE does not support :hover for anything other than <a> and was happy to use the workaround available here.

Another weird problem that I encountered with IE (versions 6 & 7).IE doesn’t seem to display text that had the color defined as ‘grey’, but, when I used the HEX value for color grey the text actually was visible. It is a bit difficult for me to put up with these issues as at home (where I mostly code), I use a mac and do not have IE (running windows a Guest OS, is something I wouldn’t want to do again), so I discover these quirks with IE when I get to work and then try to FTP to my site and try to edit files, and is getting quite painful as I am usually busy at work.

More updates, soon.I am hoping to complete some ideas that I would want to implement before I leave to NZ for a 4 day vacation.In preparation to the trip (apart from the shopping), I have decided to get rid of the tummy that could get out of control and found some help here.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Reddit
  • del.icio.us
  • Technorati
  • YahooMyWeb
  • Furl
  • Netscape
  • Fark
  • StumbleUpon
  • De.lirio.us
  • IndiaGram
  • IndianPad
  • Simpy
  • SphereIt

Recent Entries

Recent Comments

Top Posts