Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

get users IP address showing ::1

Posted on 2016-09-28
Last Modified: 2016-09-28
I am trying to echo a users IP address. If I use :


Open in new window

it outputs ::1 for some reason?
Question by:Black Sulfur
  • 4
  • 3
LVL 25

Assisted Solution

-MAS earned 100 total points
ID: 41819855
::1 is the loopback address in IPv6 is the loopback address in IPv4
Please check this for details

Author Comment

by:Black Sulfur
ID: 41819866
Okay. Let me elaborate. I want to store user's IP addresses in a database every time they try login and the login fails because either the email address or password was incorrect. I was expecting something like etc. but I don't know that ::1 is going to help as it would be nice to then see what country the ip address is coming from.
LVL 22

Accepted Solution

Ferruccio Accalai earned 400 total points
ID: 41819889
To get IP's even if behind such a Proxy or other matters you can try using one of the following functions
function get_client_ip_env() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
        $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
        $ipaddress = 'UNKNOWN';
    return $ipaddress;

Open in new window

function get_client_ip_server() {
    $ipaddress = '';
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
        $ipaddress = 'UNKNOWN';
    return $ipaddress;

Open in new window

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.


Author Comment

by:Black Sulfur
ID: 41819913
Your second example gives me undefined index errors and the first one still gives me ::1

Just to make sure I am using it correctly, I am just echoing the function name i.e.:

echo get_client_ip_env();

Open in new window


Author Comment

by:Black Sulfur
ID: 41819918
Not sure if it makes a difference, but I am using mamp on my local machine for this, not actually on a live server.
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41819937
Yes you're using it correctly.
Anyway, as MAS already said, that's the IPV6 localhost IP.
I guess you're testing some script on your local system and if so, that's why you got that IP.
I don't believe you could check the country for I guess you'd obtain a place somewhere in the world called Localhost ;-)

Author Comment

by:Black Sulfur
ID: 41819951
Okay, so this will only work on a live server?
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41819965
You could use a free dns service that points to your router and navigate to your local site using the dns given address.
For example I use free dyndns.org for this purpose

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question