Jump to content

Proxy Detection


driz
 Share

Recommended Posts

Hi, I'm working on this script that essentially boots 'undesirables' from visiting a certain webpage because they are using a proxy to hide their IP address!This is the code I have written, the idea is to include another page instead and then use exit to STOP the rest of the page rendering. BUT when I test this with a Proxy to see if it will work, the page just hangs and I get an error saying the server is taking too long to respond, I guess meaning their is an error in my code?

if (	  $_SERVER['HTTP_X_FORWARDED_FOR']   || $_SERVER['HTTP_X_FORWARDED']   || $_SERVER['HTTP_FORWARDED_FOR']   || $_SERVER['HTTP_CLIENT_IP']   || $_SERVER['HTTP_VIA']   || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554))   || @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30)){	include("/errordocument.php");	exit;}

Link to comment
Share on other sites

Try removing some of the stuff, and see where it stops hanging. In particular, the last line of the condition:

@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30))

worries me. Why leave errors unseen?Also, by default, socket connections open in blocking mode, which may be a reason for the hang. Consider first making a shorter timeout (say, 20 or 10), and setting the blocking mode to non blocking upon a successful connection, or actually close the connection explicitly.

Link to comment
Share on other sites

I've just tested it again, and its working now, I'm guessing it was the Proxy itself that was the problem.BUT could you please explain this further

Also, by default, socket connections open in blocking mode, which may be a reason for the hang. Consider first making a shorter timeout (say, 20 or 10), and setting the blocking mode to non blocking upon a successful connection, or actually close the connection explicitly.
As I didn't write the last two lines myself, would it be also possible for you to explain what they do and how they mix into what you mentioned above. Thanks Edited by driz
Link to comment
Share on other sites

Check the PHP manual, you shouldn't use code you don't understand. You should understand not only that it works, but why it works. To put it shortly, "RTFM". Look up in_array and see what it does, and look up fsockopen and see what it does.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...