How to identify each visitors country/location using php? - php

Hai friends I need user country when they visit my php website. According to his country I have to do some checking when they upload some bulk informations.
How can I find the visitor country using php.

PHP has no built-in method to determine the location of a website visitor.
The best you can do automatically is to look up their IP address in an IP-to-location database.
You can get one for free from MaxMind. They have a PHP API available for using the database.

Related

Couting IP unique visitors and sending it to mysql database

I'd like to know how can i get information about uniques IP's to my site specify link and store that information in mysql database to particular user.
I need that script count not only http://example.com.com but also ex.: http://example.com/somesub/this/link.
Because i want to develop project in which users get traffic to my system and they get paid.
(Pay to Promote system).
How can i develop this? Any ideas about php code?
First of all use $_SERVER['REMOTE_ADDR'] to find the request IP Address or see How to get client IP address PHP.
then at the start of each page of your site you should get this value (which acts like a primary key) and do query to the database to increase the specific counter.
P.S: you will find problems in case the client is using proxy to get to your site, see the link above for more information.

Trying to capture IP addresses in wordpress / php script

I would like to keep track of IP addresses visiting my site, as it helps determine what content I should host.
I a really not a programmer, so i was looking for a pre-built solution.
I found this script:
<?php
$LogFileLocation = "/public_html/cms/iplog.txt";
$fh = fopen($_SERVER['DOCUMENT_ROOT'].$LogFileLocation,'at');
fwrite($fh,date('dMy H:i:s')."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_URI']."\n");
fclose($fh);
?>
however when i created iplog.txt and browse to it, nothing happens.
If you need only statistic of visiting of your site why you don't use Google Analitics (http://www.google.com/analytics/)? It gives full information on how to track visits onto the site. Your method gives you only text file with date, user's ip and page which user visited; but if you aren't a programmer, you will not sort this information and operated this data.
If you still decide to use your method of store information and don't want to use Google Analitics, then save data about user and visited pages in the database in special created table (id, date, ip, uri). This method will permit show date-statistic, statistic for ip and single page.
You can capture IP of the visitor with the following code.
$ip=$_SERVER['REMOTE_ADDR'];
Now you can store it in your database. For that you have to create a column in your database table that stores the ip address. Along with IP address, you can store many other information in the database for keeping track of users like time stamp, duration, page visits etc. There are many tools available like Google Analytic and others which provide you such services free of cost but they don't store the record in your website's database. So choose accordingly.

How to auto re-route other country traffic except USA to a default web page?

I want to limit full functionality access to my website to users accessing it from USA only. Any users trying to access the website from any other country I want to identify that traffic based on IP or however possible that the user is not based in USA and display a default webpage like "We will be launching in your country soon" .. etc. message.
I have seen this functionality implemented by spotify.com and netflix.com and got a similar coming soon page when I tried to access the sites from India.
How do I implement this using PHP?
Thanks for any direction or insight.
You'll need to employ a geolocation service. Some are free, some are not:
Akamai, Quova, Digital Envoy (Digital Element service), Google (JavaScript), Maxmind, hostip.info, Geobytes, IP2Location, IP-GEO.
Some services you need to connect each time to make a query (you can cache the results). Other services allow you to download a database of IP-to-country mappings.

User location with PHP

I am working on a website application where it is necessary to know the location of a user when he/she posts. What would be the best method, using PHP, to determine where (general location) the user is posting from? I know you can use the user's ip with various services offered, but I am looking for something that works with users using our mobile site as well.
maybe use the browsers inbult geolocation tools? eg:
http://www.digimantra.com/howto/current-location-iphone-safari-firefox-browser/
then just parse the javascript info into your php variables?
Most sites use Accept-Language request header with $_SERVER['HTTP_ACCEPT_LANGUAGE']. If request IP also matches the language, you can be pretty sure it's the right country.
There are libraries that you can use to lookup the users location via their IP Address like http://www.geoplugin.com/webservices/php

How can i store visitor infomation like reach time ,duration of visit,and exact location of visitor in php

I want to store visitor information like reach time ,duration of visit and also exact location of the visitor.
Can any one give me any ideas about it? Please help me.
Just a few links to get you started:
JavaScript heat map generator used to track where users clicked on your site
Recording the time a user spent on any single page
Tracking the user's location via IP
Official Geolocation API specification
In my opinion, best thing would be to use some external website statistics tool (like Google Analytics or similar). You can also search for some solutions you install locally (like AWStats, in case of privacy concerns). No need to reinvent the wheel there.

Categories