April 1, 2012

limit PHP script to one domain per license

Question by Mac Os

I’m encoding my script with Ioncube and want to ensure that it works only on the licensed domain. How is this commonly done?

I was thinking something like:

function domain(){

}

if($this_domain <> domain()){
   exit('no');
}

or

$allowed_hosts = array('foo.example.com', 'bar.example.com');
if (!isset($_SERVER['HTTP_HOST']) || !in_array($_SERVER['HTTP_HOST'], $allowed_hosts)) {
    header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request');
    exit;
}

But I’m not sure if that’s correct. Would strpos be better?

Answer by Starx

This is a wasted attempt. As any determined developer can hack your code and remove the blocking algorithm.

However, as per the algorithm goes, this is fine

$allowed_hosts = array('foo.example.com', 'bar.example.com');
if (!in_array($_SERVER['HTTP_HOST'], $allowed_hosts)) {
    header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request');
    exit;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!