Page 1 of 1
PHP Licensing system
Posted: Thu Jul 14, 2011 10:15 pm
by sktanmoy
I tried to create domain based licensing. The script should be check license each time it'll run. I'll use two domain which are hosted in two different servers and networks so that if a server is down, another one will help scripts for licensing purpose.
Look at the codes bellow. It is working if "domain.net" is up. But I want the code working is any of the servers is up or contain license file. Please help me.....
Code: Select all
<?php
function checkagain(){
if (false === file_get_contents("http://domain.net/lic/ok.xml",0,null,0,1)) {
echo "Error, sorry!";
die;
}
else
{
echo "All is well";
}
}
if (false === file_get_contents("http://domain.com/lic/ok.xml",0,null,0,1)) {
echo checkagain();
}
else
{
echo "All is well";
}
?>
Re: PHP Licensing system
Posted: Thu Jul 14, 2011 10:37 pm
by Jonah Bron
Uhhh, like this?
Code: Select all
if (file_get_contents("http://domain.com/lic/ok.xml",0,null,0,1) !== false || file_get_contents("http://domain.net/lic/ok.xml",0,null,0,1) !== false) {
echo 'All is well';
} else {
echo 'Error, sorry!';
}
Re: PHP Licensing system
Posted: Thu Jul 14, 2011 11:17 pm
by sktanmoy
Jonah Bron wrote:Uhhh, like this?
Code: Select all
if (file_get_contents("http://domain.com/lic/ok.xml",0,null,0,1) !== false || file_get_contents("http://domain.net/lic/ok.xml",0,null,0,1) !== false) {
echo 'All is well';
} else {
echo 'Error, sorry!';
}
Yes, but check the output bellow:
Code: Select all
Warning: file_get_contents(http://domain.com/lic/ok.xml) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\wamp\www\ok.php on line 3
All is well
I just create a license file in domain.net and in domain.com, there is no "ok.xml". That means if any of the server goes down, the error message like above will be shown. Actually I want to display "All is well" is any of the server contain the license file.
Re: PHP Licensing system
Posted: Fri Jul 15, 2011 12:52 am
by sktanmoy
I got the solution, just @file_get_contents to suppress errors.
Re: PHP Licensing system
Posted: Fri Jul 15, 2011 7:02 pm
by Jonah Bron
That will work, but be advised that you should be very conservative about suppressing errors.
Re: PHP Licensing system
Posted: Fri Jul 15, 2011 9:23 pm
by sktanmoy
Jonah Bron wrote:That will work, but be advised that you should be very conservative about suppressing errors.
Yes, you are right, but I couldn't find any other way to fix the error. Any idea to fix the issue?
Re: PHP Licensing system
Posted: Sat Jul 16, 2011 11:37 am
by Jonah Bron
No, no, file_get_contents() is a fine time to use it. I just mean be careful about suppressing errors because they can make some bugs hard to track down
