user2183216
user2183216

Reputation: 359

getting web url address to detect web proxy

I'm trying to blocked website based proxy's. These are normally in the format of: http://3.hidemyass.com/ip-8/encoded/Oi8vZ29kbGV5ZGVzaWduLmNvLnVrL0xDcmVkaXJlY3QvZnVuY3Rpb25zL2Z1bmN0aW9

My theory of blocking these is to get the URL of the address bar and check that it's actually direct access to my site, rather than visiting via a website proxy.

However, when i try to visit my site and attempt to capture the url of the user it still reports that its my sites url.. not this web based proxy one.

I've tried the following ways of detecting it:

$url= $_SERVER['HTTP_HOST']; //get the url
$url = $_SERVER["SERVER_NAME"];

any ideas on how to resolve this?

UPDATE Ok i've rewrote part of this, however it always seems to be returning false... the $url is being passed correct as i can echo this out within the function. However it doesnt seem to be matching and returning false

<script>
var url = window.location.href;
<?php $url = "<script>document.write(url)</script>"; ?> 
</script>

<?php
//
function checkURLIsSafe($url){
    if(preg_match('/www/',$url)){
        echo 'true';
    } else {
        echo 'false';
    }
}
checkURLIsSafe($url);
?>

Upvotes: 1

Views: 723

Answers (2)

Quentin
Quentin

Reputation: 944527

PHP runs on the server. It can only see the URL that was requested from it.

hidemyass.com will be requesting the normal URL from your server. There is no way to tell what URL the browser requested from hidemyass.com.

Approaches you could take include:

  • Checking the source ip against a list of known proxies
  • Using client-side JavaScript to read location.href

Upvotes: 1

drull
drull

Reputation: 509

You cant do it with PHP only. What you can do is to check window.location.href with javascript, and if it's incorrect, send ajax request to server, which will block IP address.

Upvotes: 1

Related Questions