Let's begin this little problem by determining what we can deduce for certain from the remote server. Now, unfortunately, because of the way the Interweb works, the only single piece of data that we can know for sure is the IP address of the remote server initiating the request. We could, in theory, rely on the web address as well from the
$_SERVER array. However, what if the user were to do this at the top of the script:
php Code:
$_SERVER['HTTP_HOST'] = '.talkphp.com';
That would, in practice, modify the script's web address in the
$_SERVER array and therefore be impractical to be used to secure an entire script.
If we consider though that any web address is associated with an IP address, and as the server makes the request with the IP address in the HTTP packet, this cannot be successfully forged because the packet would not be sent back to the correct location. Thus, if we were to tie the domain to the IP address, then in theory this would be a concrete solution. The packet may look something like so, in pseudo terms:
Code:
License Key: fe0a4
WAN IP Address: 80.128.4.50
Web Address: .talkphp.com
Then within the remote database you would have successfully tied a web address to the IP address, and therefore you can now send the web address using the
$_SERVER array because if the corresponding IP address does not match then you can assume it is an attempt at cheating the system.
Now, another problem that crops up from the above is what if the initial request to register their license key is fed through a proxy, and thus tying the web address .talkphp.com to a publicly available open proxy. Like this:
Code:
License Key: fe0a4
Proxy IP Address: 80.128.4.51
Web Address: .talkphp.com
I'm sure it's clear now that the IP address, because anybody can relay through it, is useless. As long as they set the
$_SERVER['HTTP_HOST'] to the web address in which the license was registered via, then they've successfully overcome the feeble security.
Nonetheless, there is something you can do above that! If you perform a lookup on the web address which the script is supposedly running on, you could ensure that the IP address which the script is claiming to be running on, matches the domain's IP address via the lookup request. Here are the results from a typical "nslookup" on talkphp.com:
Quote:
|
Originally Posted by nslookup
Non-authoritative answer:
Name: talkphp.com
Address: 64.22.89.218
|
Thus the remove part of the script, based on your server, must ensure that the IP address 64.22.89.218 matches the IP address the license registered has been initiated from. If it does not match then you should not continue.
The potential downsides to this approach I see are negligible, but there are issues. Namely, if the script is based on the same server, and they knew one another, then they could quite easily modify the script to change the
$_SERVER['HTTP_HOST'] array. This is where the encryption would come in for your script. Using an application such IonCube, you could encrypt the license segment of the code, and any other important files, and therefore resultantly preventing users to tamper with your script.
I'm become quite tired at the moment, but I believe that's a really good foundation. My mind has just gone numb, but I was going to go into the possibility of storing files remotely and using
eval() to execute the script, but this requires some more thinking about. It all depends on how secure you require it to be.