Jump to content

PHP IP Address.


AshleyByrom

Recommended Posts

Well, on my previous post I mentioned I am making a basic user login script.

 

I am trying to log IP's a user logs in from but I am stuck at the first hurdle.

 

After a goole search I have tried using

<?php 
//Gets the IP address
$ip = getenv("REMOTE_ADDR") ; 
Echo "Your IP is " . $ip; 
?>

 

but when I use that I am given:

Your IP is ::1

 

any help?

 

 

Link to comment
https://forums.phpfreaks.com/topic/166541-php-ip-address/
Share on other sites

Oh.. now it works?

 

That is highly confusing.

 

I am running apache with PHP on my mac and I also have an external server I am accessing via FTP.

 

Maybe on Apache it doesn't work but on the external server it does. Freaky but, i dont have to worry now. Thanks anyway! :)

Link to comment
https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878257
Share on other sites

Read up on this thread: http://www.phpfreaks.com/forums/index.php/topic,260768.msg1229279.html

 

function getip() {
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
         return $_SERVER['HTTP_CLIENT_IP']; // shared internet
    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         return $_SERVER['HTTP_X_FORWARDED_FOR']; // behind a proxy
    } else {
         return $_SERVER['REMOTE_ADDR']; // directly connected to the internet
    }
}

 

This gives you the the ip address when the user uses shared internet, a proxy or is just directly connected to the internet.

Link to comment
https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878273
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.