Jump to content

Code for visitors watching my website


phpmady

Recommended Posts

GeoIP is a complicated code to use.

 

<?php
/**
* GeoIP Country Database Example
*
* @version $Id$
* @package geoip
* @copyright © 2006 Lampix.net
* @author Dragan Dinic <dinke@lampix.net>
*/

require_once("geoip.inc");

$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);

$ip = $_SERVER['REMOTE_ADDR'];
//if you test on localhost use IP bellow for test
//since $_SERVER['REMOTE_ADDR'] would be 127.0.0.1
//$ip = "89.216.226.174";

$country_name = geoip_country_name_by_addr($gi, $ip);
$country_code = geoip_country_code_by_addr($gi, $ip);
if($country_name)
{
echo "Your country is: $country_name <br />";
echo "Country Code is: $country_code <br />";
}
else
{
echo "Sorry, we weren't able to locate you.";
}

geoip_close($gi);
?>

 

http://geolite.maxmind.com/download/geoip/api/php/geoip.inc

save that

and download this

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

 

Place them in the same folder as the script.

Link to comment
Share on other sites

GeoIP is a complicated code to use.

 

<?php
/**
* GeoIP Country Database Example
*
* @version $Id$
* @package geoip
* @copyright © 2006 Lampix.net
* @author Dragan Dinic <dinke@lampix.net>
*/

require_once("geoip.inc");

$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);

$ip = $_SERVER['REMOTE_ADDR'];
//if you test on localhost use IP bellow for test
//since $_SERVER['REMOTE_ADDR'] would be 127.0.0.1
//$ip = "89.216.226.174";

$country_name = geoip_country_name_by_addr($gi, $ip);
$country_code = geoip_country_code_by_addr($gi, $ip);
if($country_name)
{
echo "Your country is: $country_name <br />";
echo "Country Code is: $country_code <br />";
}
else
{
echo "Sorry, we weren't able to locate you.";
}

geoip_close($gi);
?>

 

http://geolite.maxmind.com/download/geoip/api/php/geoip.inc

save that

and download this

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

 

Place them in the same folder as the script.

 

Hi,

 

Thank you for your code, but what i need is, displaying all the users ipaddress and country flag  who are viewing my website online.

 

Thank You

 

 

Link to comment
Share on other sites

Hi,  had posted a solution to help those who wanted country based flags displayed on their site. Unfortunately they were myopically removed.

 

But here is how to do it.

 

make a folder on your website named "geoip" then go the the site where the free geoip is located. Download the dat file

http://www.maxmind.com/app/geolitecountry

under link named "Download the latest GeoLite Country Binary Format"

uncompress it and save it to the geoip folder.

 

Then go here

http://geolite.maxmind.com/download/geoip/api/php/

and save all the .hph and .inc files to the geoip folder.

 

Here is a function that I wrote that is a bit easier to use and includes a flag img tag.

 

<?php
//function usage
// function(1,2,3)
//1 is the ip address
//2 is the method - short|long
//short = US
//long=Unites States
//3 is the image will we return it or not
//image = yes|no
// RETURN
//the function return an array,
//array[0] is the textual representation of the country
//array[1] is the image tag
//$array=get_flag($ip,short,yes);
//sample vars for function
//$ip='24.24.24.24';
//$method_type='short';
//$image_use='yes';
//
function get_geoip($ip,$method_type,$image_use)
{

$array=array();

include("./geoip.inc");

$gi = geoip_open("./GeoIP.dat",GEOIP_STANDARD);

$country_code = geoip_country_code_by_addr($gi, "$ip");
$country_name = geoip_country_name_by_addr($gi, "$ip");
geoip_close($gi);

$cc=strtolower($country_code);
$img_str = "<img src=\"./flags/$cc.png\" border=0>";

//geoip_close($gi);

if($method_type == 'short')$array[0]=$country_code;
if($method_type == 'long')$array[0]=$country_name;
if($image_use == 'yes')$array[1]=$img_str;

return $array;
}

$ip='24.24.24.24';
$returned_array=get_geoip($ip,'long','yes');
print_r($returned_array);
?>

 

If you have any questions just ask.

 

 

HTH

Teamatomic

 

Link to comment
Share on other sites

Thank You for your post teamtonic, its so nice to go step by step,

 

 

where can i download the flags

 

 

one more thing, i am happy what i have done,

 

whethet it will show

 

 

Users Online :: STATUS

 

No  ipaddress      country      flag

1    27.23.25.9      france      france flag

2    27.23.25.91    italy          italy flag

3    27.23.25.92    nepal        nepal flag

 

can i get like this result...

Thank You

 

 

 

 

Link to comment
Share on other sites

Hi, flags are all over the place but good ones can be a bit harder to find. I'll attach the ones I use.

 

 

HTH

Teamatomic

 

 

Hi,

 

 

I like to have list of visitors online with their country flags, is it possible,

 

where i have attached my result and one i need, Pls go through the atachment, and you will find it what i need.

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.