I'm developing a PHP app which needs to be locked down to a particular server IP address so that people cannot easily copy it to other servers. The application will be installed on an internal server at the client's office.
I have an encoded license file with the allowed server IP address stored in it, and on the login page I want to check that this matches the IP of the server.
To do this I use the following code:
if(getHostByName(getHostName()) != $licensedServerIp){
throw new Exception("The server's IP address does not match that in your license file.");
}
This works nicely on my development machine, but are there any situations that I need to look out for where this function would fail? I have no idea what the function is actually doing in the background - could certain network issues stop this from working?
No.
Please follow the links given below:
http://php.net/manual/en/function.gethostbyname.php
https://bugs.php.net/bug.php?id=63730
https://bugs.php.net/bug.php?id=8754
Its recommended, not to use it in production sites