Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   Internet Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=25)
-   -   php? detecting ip of NTL user? (https://www.cableforum.uk/board/showthread.php?t=31782)

dragon 12-07-2005 07:32

php? detecting ip of NTL user?
 
My friend has a site portal on his site which features a shoutbox

, problem is the shoutbox is logging the visiting IP of an NTL user as the ip of the proxy cache, (it does this when you post a shout) obivously if someone ended up causing trouble and my friend was to ban the IP he'd end up banning the whole cache instead.


i was wandering if theres something he can add to his could add to his code so that the true ip was determaned rather than that of the proxy cache?

Jon M 12-07-2005 08:15

Re: php? detecting ip of NTL user?
 
You're saying he coded this shoutbox himself?

If he did, then surely he can find this out for himself?
If not, who made it? and have you asked the question to them?

The php code for displaying the end user IP is:
Code:

<? echo getenv('REMOTE_ADDR'); ?>
__________________

This code will detect whether it is a forwarded (behind a proxy) address:
Code:

**Ignore this, it's useless ASP code**

philip.j.fry 12-07-2005 10:10

Re: php? detecting ip of NTL user?
 
Quote:

Originally Posted by Jon M
This code will detect whether it is a forwarded (behind a proxy) address:
Code:

Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If sIPAddress="" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")
EndIf


Isn't that VB rather than PHP? :confused:

punky 12-07-2005 10:16

Re: php? detecting ip of NTL user?
 
Quote:

Originally Posted by philip.j.fry
Isn't that VB rather than PHP? :confused:

I thought it was ASP.
__________________

The most robust way of doing it that I have seen is this:

PHP Code:

function getip() {
if (isSet(
$_SERVER)) {
 if (isSet(
$_SERVER["HTTP_X_FORWARDED_FOR"])) {
  
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
 } elseif (isSet(
$_SERVER["HTTP_CLIENT_IP"])) {
  
$realip = $_SERVER["HTTP_CLIENT_IP"];
 } else {
  
$realip = $_SERVER["REMOTE_ADDR"];
 }

} else {
 if ( 
getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
  
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
 } elseif ( 
getenv( 'HTTP_CLIENT_IP' ) ) {
  
$realip = getenv( 'HTTP_CLIENT_IP' );
 } else {
  
$realip = getenv( 'REMOTE_ADDR' );
 }
}
return 
$realip;
} 

From here:

http://board.php-princess.net/index....=ST&f=10&t=14# second post down, by pootergeist. Haven't tried it, looks pretty good though.

Jon M 12-07-2005 10:19

Re: php? detecting ip of NTL user?
 
Lol, ASP, how did I not spot that :rofl: :disturbd:
Trying to be too fast with google.

philip.j.fry 12-07-2005 10:25

Re: php? detecting ip of NTL user?
 
Quote:

Originally Posted by punky
I thought it was ASP.

Doh me :dunce: never used ASP or VB before but I knew that Dim was the way to declare variables in VB (edit: unless it isn't and I'm completely wrong :D ).

Gareth 12-07-2005 12:42

Re: php? detecting ip of NTL user?
 
<pedantic>ASP just stands for Active Server Pages, which is a technology that uses VBScript and/or Javascript and/or perl and/or any other scripting language you like. ASP itself is not a language. </pedantic>

Just thought I'd clear that up.

philip.j.fry 12-07-2005 13:52

Re: php? detecting ip of NTL user?
 
Quote:

Originally Posted by Gareth
<pedantic>ASP just stands for Active Server Pages, which is a technology that uses VBScript and/or Javascript and/or perl and/or any other scripting language you like. ASP itself is not a language. </pedantic>

Woohoo, I was only partially wrong then :D


All times are GMT. The time now is 12:49.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum