开发者

PHP Doamin based licensing system

I tried to create a domain based licensing system. The script should be check for license each time it'll be run. I'll use two domains which are hoste开发者_运维知识库d in two different servers and networks so that if a server is down, another one will help the scripts for licensing purpose. Look at the codes bellow...

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!';
}

And output:

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 created a license file in domain.net. In domain.com, there was 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 servers contains the license file.

So how my code should be re-written? Which function should I use? Please help me.

PS: I'm fully new here and not known with rules of this types of community. So please help me to go on. Don't close the topic directly, help me to find out the correct way to post/ask questions.


Use @file_get_contents to suppress errors.

However, doing a remote HTTP request on every page load is pretty much unacceptable. If your server (or one of them) is slow the site doing the requests will be slow, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜