0
<?php

    require 'connection.php';

    $user_ip = $_SERVER['REMOTE_ADDR'];
    echo $user_ip;

?>

Output being displayed

::1

I am just practicing to get the visitor ip to count that how many vistors have visit the website.

Kheshav Sewnundun
  • 1,236
  • 15
  • 37
  • 1
    possible duplicate of [Should a MAMP return ::1 as IP on localhost?](http://stackoverflow.com/questions/3699454/should-a-mamp-return-1-as-ip-on-localhost) – Rizier123 Feb 23 '15 at 06:29

2 Answers2

0

This is because your webserver is listening on ipV6.

Try the following:

  • Find your webserver configuraion (httpd.conf)
  • Look for the line

Listen 80

  • Change it to 0.0.0.0:80 so it looks as follows:

Listen 0.0.0.0:80

Reff

Kheshav Sewnundun
  • 1,236
  • 15
  • 37
  • # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 127.0.0.1 where to change i have changed at last line 8o to 127.0.0.1 and after stoping services i restart my server but it is not working server icon is showing working – Shams Bilal Feb 23 '15 at 06:59
0

Much simple one:

<?php
    $user_ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
    echo $user_ip;
?>
Ataboy Josef
  • 2,087
  • 3
  • 22
  • 27
  • Here(http://stackoverflow.com/questions/18799808/how-do-i-count-unique-visitors-to-my-site) is the full solution for your problem. – Ataboy Josef Feb 23 '15 at 06:40