driz Posted June 2, 2009 Share Posted June 2, 2009 Hi, I've been playing with this code, that gets the users REAL ip address: <?php function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; }?> How can I edit this code so that IF the user is using a proxy I can show an error message such as 'Not allowed to access this page using Proxies' and if they are just using a normal everyday ip then no error will occur. I'm guessing I just replace the $ip variables with my message. But I want an efficient way of doing this, such as showing a whole page BUT not redirecting just showing the error page instead, like what happens if you get a 404, you dont redirect rather you just get the error page on that the problomatic URL. Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 2, 2009 Share Posted June 2, 2009 If the proxy IP is given then you can just print an error message and exit right there. Is there a reason you need to save the error message to print it later? Link to comment Share on other sites More sharing options...
Synook Posted June 3, 2009 Share Posted June 3, 2009 Or you could send a 400-series header, but you have to do that before output. Link to comment Share on other sites More sharing options...
driz Posted June 3, 2009 Author Share Posted June 3, 2009 Or you could send a 400-series header, but you have to do that before output.Could you explain this further please, as I don't know how you'd do that. thanks Link to comment Share on other sites More sharing options...
Synook Posted June 3, 2009 Share Posted June 3, 2009 header("HTTP/1.0 403 Forbidden"); That will send a 403 Forbidden header. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.