How to get IP address / location of connecting visitors to my website, and show THEIR addresses to me?

StackOverflow https://stackoverflow.com/questions/21203342

Question

i am looking for help in this problem. I know how to get IPv4 address in PHP code, like this:

$ip = $_SERVER['REMOTE_ADDR'];

this is what i found as answer for many questions like this here, but if i go to the website, it only shows MY ip address, if my friend goes to the website he sees only his ip address. The thing is, i will have administrator interface on the website, and i need to determine the ip address of all connecting clients - either in php or javascript and display it on my website in the admin interface. On server apache is running. Is there any way to do it?

Était-ce utile?

La solution

I think you want to get the user IP address and location of the IP address who is visiting your website and other details.

// get user details
        $user_agent = $_SERVER['HTTP_USER_AGENT']; //user browser
        $ip_address = $_SERVER["REMOTE_ADDR"];     // user ip adderss
        $page_name = $_SERVER["SCRIPT_NAME"];      // page the user looking
        $query_string = $_SERVER["QUERY_STRING"];   // what query he used
        $current_page = $page_name."?".$query_string; 


    // get location 
        $url = json_decode(file_get_contents("http://api.ipinfodb.com/v3/ip-city/?key=/*userapikey*/
        // you can get your api key form http://ipinfodb.com/
        ip=".$_SERVER['REMOTE_ADDR']."&format=json"));
        $country=$url->countryName;  // user country
        $city=$url->cityName;       // city
        $region=$url->regionName;   // regoin
        $latitude=$url->latitude;    //lat and lon
        $longitude=$url->longitude;

    // get time
        date_default_timezone_set('UTC');
        $date = date("Y-m-d");
        $time = date("H:i:s");

you can now store these in database it will tell you the location, user browser and which page he/she is using

Autres conseils

When someone visits the site, put the value of $ip in a database.

When you want to see who has visited the site, loop over the contents of the database and display them.

You'll probably also want to include a timestamp and delete old data periodically and/or ignore data over a certain age (such as 5 minutes).

Well, both see your own IP because you're just parsing the IP of the visitor, you need to save this Remote Address in a table, then just do a query to retrieve the content put a limit on your query this is very important, and then just parse the result and here you go, a list of the vistors

I needed to track ip address and location of visitors to my site, to identify fraud clicks in google adwords campaigns. This product does the job, unfortunately its not free. Please see if this would solve you issue.

http://www.opentracker.net/products/web-analytics/feature/ip-address-tracking

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top