Thursday, May 14, 2009

PHP: How to detect if your client is using proxy?

Many times happened that your page is browsing using proxy. Do you want to check whether your user is using a proxy to browse your page? There is a way at PHP to detect whether about this proxy issue. Its handy too.

Using the HTTP_VIA field from your $_SERVER variable, you can easily get the string value. It will tell you whether your user is came to your site via any gateway or via a proxy server or anything.

But this is only available if the gateway forward the information to server. Otherwise it will not be possible for you to detect. There are lots of open free proxy, and many of them are forward the information to server. So if people are using those proxies, you can easily detect them. Here is a sample code to do this. This will print the string if it is available.

if( isset($_SERVER['HTTP_VIA']) ){
print $_SERVER['HTTP_VIA'];

The sample output can be : (Squid/2.4.STABLE7)

But this can be various types of string output. If the string is not empty, 80% cases you can be assure that user is using a proxy server. You can't make sure 100% that the user is really using a proxy server.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...