基于PHP域的许可系统
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 hosted 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.
我尝试创建基于域的许可系统。 该脚本应在每次运行时检查许可证。 我将使用托管在两个不同服务器和网络中的两个域,这样如果服务器关闭,另一个将帮助脚本进行许可。 看看下面的代码... p>
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'一切都很好';
}其他{
echo'错误,抱歉!';
}
pre>
输出: p>
警告:file_get_contents(http://domain.com/lic/ok.xml)[ function.file-get-contents]:无法打开流:HTTP请求失败! 在第3行的C:\ wamp \ www \ ok.php中找不到HTTP / 1.1 404
很好
code> pre>
我刚刚在域中创建了一个许可证文件。 净。 在domain.com中,没有“ok.xml”。 这意味着如果任何服务器出现故障,将显示如上所述的错误消息。 实际上我想显示“All is well”是任何包含许可证文件的服务器。 p>
那么我的代码应该如何重写? 我应该使用哪种功能? 请帮助我。 p>
PS:我在这里是全新的,并且不了解这类社区的规则。 所以请帮我继续。 不要直接关闭主题,请帮助我找出发布/提问的正确方法。 p>
div>
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.