driz Posted June 22, 2009 Share Posted June 22, 2009 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 More sharing options...
boen_robot Posted June 22, 2009 Share Posted June 22, 2009 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 More sharing options...
driz Posted June 22, 2009 Author Share Posted June 22, 2009 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2009 Share Posted June 22, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.