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){
 //download the Geo DB file from
$handle = fopen("IpToCountry.txt", "r");
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; }
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.

Pagination issue in Pligg

—-This post is part of my effort to document issues that I face while using Pligg.—-
As the number of posts increase at (I have got nothing else to do!), I noticed something that was not right (which I kinda ignored before). As the number of posts became greater that the number of posts that were meant to be one page, I expected a link down at the bottom of the page that would have directed me to older submissions (pagination). That did not occur, after some searching, I came across a Post in the Pligg forum that directed me to download the Admin Total Plugin, that kind of regenerates the total no of pages ;submitted, queued and discarded. after installing and clicking on Regenerate Totals link twice, I was able to fix the issue. If you are unable to see page links in Pligg and have

 do_pages($rows, $page_size, "published");  

uncommented in index_center.tpl , then defintely download the plugin and give it a try.