Asked  7 Months ago    Answers:  5   Viewed   29 times

Possible Duplicate:
Function to get user ip address

<?PHP

$ipaddress = $_SERVER["REMOTE_ADDR"];

echo "Your IP is $ipaddress!";

?>

I was told this way of getting ip address has issues such as being able to fool. Is there a better way to gather ip address? looking for tutorials of better way to get ip address?

 Answers

66

$_SERVER['REMOTE_ADDR'] is the only reliable IP address you'll get - it's extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you'll get the proxy's address, not the user's.

Any of the other header-based ones are unreliable, as HTTP headers are trivial to forge. You can use the information from them, if you'd like, as long as you don't TRUST it.

Wednesday, March 31, 2021
 
viper
answered 7 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 7 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
51

Well, your function should behave as expected, but here are some suggestions:

// lowercase first letter of functions. It is more standard for PHP
function getIP() 
{
    // populate a local variable to avoid extra function calls.
    // NOTE: use of getenv is not as common as use of $_SERVER.
    //       because of this use of $_SERVER is recommended, but 
    //       for consistency, I'll use getenv below
    $tmp = getenv("HTTP_CLIENT_IP");
    // you DON'T want the HTTP_CLIENT_ID to equal unknown. That said, I don't
    // believe it ever will (same for all below)
    if ( $tmp && !strcasecmp( $tmp, "unknown"))
        return $tmp;
        
    $tmp = getenv("HTTP_X_FORWARDED_FOR");
    if( $tmp && !strcasecmp( $tmp, "unknown"))
        return $tmp;
        
    // no sense in testing SERVER after this. 
    // $_SERVER[ 'REMOTE_ADDR' ] == gentenv( 'REMOTE_ADDR' );
    $tmp = getenv("REMOTE_ADDR");
    if($tmp && !strcasecmp($tmp, "unknown"))
        return $tmp;
        
    return("unknown");
}
Wednesday, July 28, 2021
 
phpmeh
answered 3 Months ago
46

If you have your own DNS server you can block domains from resolving. Here is a guide to block domains in Bind DNS server.

To get all the IP addresses there is no way. What you can do is, install dig. It's available in linux but not in windows.

Then time to time enter dig youtube.com. It'll show you all the resolved IPs from DNS cache.

See my result

$ dig youtube.com A

; <<>> DiG 9.7.0-P1 <<>> youtube.com A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13442
;; flags: qr rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;youtube.com.                   IN      A

;; ANSWER SECTION:
youtube.com.            83      IN      A       74.125.235.47
youtube.com.            83      IN      A       74.125.235.46
youtube.com.            83      IN      A       74.125.235.45
youtube.com.            83      IN      A       74.125.235.44
youtube.com.            83      IN      A       74.125.235.43
youtube.com.            83      IN      A       74.125.235.42
youtube.com.            83      IN      A       74.125.235.41
youtube.com.            83      IN      A       74.125.235.40
youtube.com.            83      IN      A       74.125.235.39
youtube.com.            83      IN      A       74.125.235.38
youtube.com.            83      IN      A       74.125.235.37
youtube.com.            83      IN      A       74.125.235.36
youtube.com.            83      IN      A       74.125.235.35
youtube.com.            83      IN      A       74.125.235.34
youtube.com.            83      IN      A       74.125.235.33
youtube.com.            83      IN      A       74.125.235.32

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Feb 18 22:26:58 2012
;; MSG SIZE  rcvd: 285
Sunday, September 5, 2021
 
giser_yugang
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :