RE: [PHP] Getting a client's IP address
| From: | Jon Haworth | Date: | Tue, 16 Oct 2001 11:00:52 +0000 |
| Subject: | RE: [PHP] Getting a client's IP address | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71194@lists.php.net to get a copy of this message | ||
A better method is to use:
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ip=getenv(HTTP_X_FORWARDED_FOR);
} else {
$ip=getenv(REMOTE_ADDR);
}
This way you don't pick up the proxy address. If you then want to only allow
access from certain IPs you can use something like:
if (!strstr($ip, "192.168.0.")) {
header("HTTP/1.0 403 Forbidden"); exit;
}
this would only allow people with 192.168.0.x IPs (common for LANs) to
access your page.
If you're running Apache you might also like to look at
order deny,allow
deny from all
allow from mydomain.com
Cheers
Jon
-----Original Message-----
From: Dave Watkinson [mailto:d.watkinson@mightymatch.com]
Sent: 16 October 2001 11:36
To: Brian Aitken; php-general@lists.php.net
Subject: RE: [PHP] Getting a client's IP address
$remoteip = getenv ("REMOTE_ADDR");
-----Original Message-----
From: Brian Aitken [mailto:b.aitken@hatii.gla.ac.uk]
Sent: 16 October 2001 11:42
To: php-general@lists.php.net
Subject: [PHP] Getting a client's IP address
Hiya
Anyone know if it's possible to get the client's IP address?
What I'm wanting to do is be able to differentiate between users
accessing
the system from the local intranet and users accessing the system from
anywhere else.
I've looked through the documentation and the only thing I could find
was a
user note that says:
"I filed a wishlist bug because I do not see any way to get the IP
address
of the client."
Anyone know if this is the case and if so is there another way to limit
access to local users?
Thanks
Brian
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
**********************************************************************
'The information included in this Email is of a confidential nature and is
intended only for the addressee. If you are not the intended addressee,
any disclosure, copying or distribution by you is prohibited and may be
unlawful. Disclosure to any party other than the addressee, whether
inadvertent or otherwise is not intended to waive privilege or confidentiality'
**********************************************************************