4

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?

1
  • Save them to the database table is an option ? Commented Jan 18, 2014 at 11:19

3 Answers 3

17

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

Sign up to request clarification or add additional context in comments.

2 Comments

I am not sure about one think. OK, i need to create a database where i will store the data (the IP address and/or the location of connecting users), but how will i tell the database to store all the values? I mean do i need to loop through somehow through the $ip = $_SERVER['REMOTE_ADDR'] to get all the values from it and than store them seperatly? I am a bit confused
you can store where value in the database by the sql querry. and the will be no need to run a loop for this.
2

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).

4 Comments

In addition, you will probably also want to store their current location on the website. You can find that by looking at $_SERVER['REQUEST_URI'].
I am not sure about one think. OK, i need to create a database where i will store the data (the IP address and/or the location of connecting users), but how will i tell the database to store all the values? I mean do i need to loop through somehow through the $ip = $_SERVER['REMOTE_ADDR'] to get all the values from it and than store them seperatly? I am a bit confused
"how will i tell the database to store all the values" — Each time someone visits the page, you store the IP they used to visit it.
"do i need to loop through somehow through the $ip = $_SERVER['REMOTE_ADDR'] to get all the values" — No, the visitor's request will only be coming from one IP, so there is nothing to loop over.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.