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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.