PHP help (in Off-topic)

AdminTal Destra April 8 2009 10:18 AM EDT

IF ( getenv("HTTP_CLIENT_IP") && strcasecmp( getenv("HTTP_CLIENT_IP"), "unknown" ) )
$IP = getenv("HTTP_CLIENT_IP");
ELSEIF ( getenv("HTTP_X_FORWARDED_FOR") && strcasecmp( getenv("HTTP_X_FORWARDED_FOR"), "unknown" ) )
ELSEIF ( getenv("REMOTE_ADDR") && strcasecmp( getenv("REMOTE_ADDR"), "unknown" ) )
$IP = getenv("REMOTE_ADDR"); ELSEIF ( isset( $_SERVER['REMOTE_ADDR'] ) && $_SERVER['REMOTE_ADDR'] && strcasecmp( $_SERVER['REMOTE_ADDR'], "unknown" ) )

now why doesn't it work?

blackshadowshade April 8 2009 10:26 AM EDT

Tal, I presume you can test each condition separately. Which one is active? what is your error message?

AdminTal Destra April 8 2009 10:28 AM EDT

oh maybe i should specify its sending back blanks for ips

blackshadowshade April 8 2009 10:32 AM EDT

That first condition looks funny to me.

IF ( getenv("HTTP_CLIENT_IP") && strcasecmp( getenv("HTTP_CLIENT_IP"), "unknown" ) )

Do you want a NOT on the second condition?

Spell checker really doesn't like coding words at all.

AdminTal Destra April 8 2009 10:34 AM EDT

attempting to ban proxy ips

blackshadowshade April 8 2009 11:07 AM EDT

Tal, I ran your script as you have it there.

I'm using a toy IP address, and it appears:

"print $IP" gives me

which is correct.

What exactly is not working for you? What sort of inputs are failing?

blackshadowshade April 8 2009 3:29 PM EDT


if( @fsockopen( $_SERVER['REMOTE_ADDR'], 80, $errstr, $errno, 1 ) ) { die("I'm not letting you in"); }

i.e. check for a connection to port 80

bartjan April 8 2009 4:16 PM EDT

I haven't touched any PHP in about 1.5 years now (sounds like an AA meeting :) but here goes:

if (isset($_SERVER['HTTP_CLIENT_IP']) && !strcasecmp($_SERVER['HTTP_CLIENT_IP'],"unknown")) $IP=$_SERVER['HTTP_CLIENT_IP'];
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'],"unknown")) $IP=$_SERVER['HTTP_X_FORWARDED_FOR'];
elseif (isset($_SERVER['REMOTE_ADDR']) && !strcasecmp($_SERVER['REMOTE_ADDR'],"unknown")) $IP=$_SERVER['REMOTE_ADDR'];
else $IP=FALSE;

But I'm not getting what you want to achieve with this code.

Warlord, that code sample you show would block me from accessing a website that uses that code. for example runs on the same Internet connection as I am using to browse with...
This thread is closed to new posts. However, you are welcome to reference it from a new thread; link this with the html <a href="/bboard/q-and-a-fetch-msg.tcl?msg_id=002iNv">PHP help</a>