FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

How to get the IP address of People who Visit my Site

 


Possum
Hi

Is there anyway I can get the IP address of a visitor to my site.

Also once I have that IP address, can I find out where that IP address is from, down to the Town, City, Country.

Thank you...
wumingsden
Possum wrote:
Hi

Is there anyway I can get the IP address of a visitor to my site.

Also once I have that IP address, can I find out where that IP address is from, down to the Town, City, Country.

Thank you...


Personally, in most cases I think its a bad idea to collect IP addresses of visitors.
But thats just my opinion. Make sure you have something in your privacy policy about it though

Do a quick search on the php functions long2ip and ip2long and the mySql inet_aton and inet_ntoa functions.

Alternatively, if you want the visitor to fill in a form, and that informaion along with their ip address is sent to you, use this code -

Code:
function GetUserIP() {
if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{ $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; }
elseif(isset($_SERVER["HTTP_CLIENT_IP"]))
{ $ip = $_SERVER["HTTP_CLIENT_IP"]; }
else { $ip = $_SERVER["REMOTE_ADDR"]; }
}
else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) )
{ $ip = getenv( 'HTTP_X_FORWARDED_FOR' ); }
elseif ( getenv( 'HTTP_CLIENT_IP' ) )
{ $ip = getenv( 'HTTP_CLIENT_IP' ); }
else { $ip = getenv( 'REMOTE_ADDR' ); }
}
return $ip;
}


I haven't been able to be active much recently, but if you want to get the ip address from a frihost-hosted website, there is possibly a feature in your cPanel/directadmin
Possum
Thank you

I understand your concern that you may think I want to spy on people who visit my site.

I am actually researching how advertisers can know how to target advertising to a locality.

I believe they must do this from getting the uers IP address..
AftershockVibe
The code wumingsden posted above shouldn't require a form submission to work. PHP can use those environment variables for normal pages.

However, one caveat is that the server has no way of knowing how many layers of redirection are between you and the client. I'll not go into how NAT (wiki link) works but your server will only report the final IP address (the only one it is aware of). Routers, proxy servers and ISP gateways use NAT quite often. This should be mostly fine for what you are doing - a router and any transparent proxys used by ISPs will tend to be in the same country.

That's about as far as it goes though. A lot of advertisers have tried to be more specific and go for city names. These, at least for the UK, are usually wildly inaccurate.
Laughing
Possum
I was just thinking..

Does that code need to go into each of my web pages..

Or is there a way for the server to do this

Thank You
Hogwarts
Possum wrote:
I was just thinking..

Does that code need to go into each of my web pages..

Or is there a way for the server to do this

Thank You


Yes, it does, unless you use an include.
silverdown
I use BBclone.de it does what you want plus ALOT more! Very Happy
Diablosblizz
If you have a header file just add it into there and bam you've got yourself a IP logger. Smile
albuferque
Geolocation class can be used to determine the geographic location of an IP address using the hostip.info Web services.

The class is guaranteed to work with PHP version 4.2 and PHP 5.2. It accesses the hostip.info Web services API site passing a given host IP address as query parameter.

The class retrieves and parses the response to return the country, the city, and the latitude and longitude coordinates of the specified host.

More details here:

http://www.phpclasses.org/browse/package/3813.html
loyal
Possum wrote:
Hi

Is there anyway I can get the IP address of a visitor to my site.

Also once I have that IP address, can I find out where that IP address is from, down to the Town, City, Country.

Thank you...


Peace.

Why don't you just use a proper service? I recommend statcounter. (http://www.statcounter.com)
zhicheng
you can use google analytics, It's cool
akaichen
zhicheng wrote:
you can use google analytics, It's cool


i think same with you. with me google always is the best Razz
Related topics

1 ip address = 1 soul
Software for anonymous IP address
Best IP Address Geographical Locator?
Purchasing a dedicated IP Address?
ip address

Frihost.com Ip Address
IP Address HTML CODE
Filtering your IP Address from the Webilizer Stats
how to make a new ip address!
IP Address Banning ( Not using .htaccess)

A good way to see your computer IP address
Dns server on a dynamic ip address?
DNS server for dynamic ip address?
ip address
Where can I obtain static IP Address ?
Reply to topic    Frihost Forum Index -> Scripting -> Website Software

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.