Home > Article > Backend Development > How to add domain name authorization to php source code
php is the most popular language in the field of web development and is also the best choice for development projects. Many PHP developers say it is the best development language in the world today. PHP development projects are highly efficient because there are too many open source projects. Now, whether domestic or foreign, there are too many open source frameworks, open source CMS systems, and open source mall systems, so the PHP ecosystem is very good.
If you want to open source the project, you need to implement a simple copyright protection on the source code. The code can be open source, but the copyright and ownership of the project are yours.
The domain name authorization code can be encapsulated into a function or encrypted. There are methods to crack the commonly used PHP encryption forms, such as ZendGuard, ionCube, etc. If there are many authorized domain names, you can Add a domain name field to the project, write the domain name to the database, and then read and verify it. You can encapsulate this method into a class or plug-in. (Recommended learning: PHP video tutorial)
Let me share two codes with you so that you can learn about them.
1. Method of independently verifying domain name authorization:
function allow_domain(){ $is_allow=false; //获取不带端口号的域名前缀 $servername=trim($_SERVER['SERVER_NAME']); //授权域名列表 $Array=array("www.yunmasucai.com","www.zzphp.cn"); //遍历数组 foreach($Array as $value){ $value=trim($value); $domain=explode($value,$servername); if(count($domain)>1){ $is_allow=true; break; } } if(!$is_allow){ die("域名未授权!"); //授权失败 }else{ echo "域名已授权!"; //授权成功 } } allow_domain();
2. Method of online verification of domain name authorization:
/* * 服务端代码 */ //获取域名 $domain = $_GET['domain']; //授权域名列表 $Array = array('www.yunmasucai.com','www.zzphp.cn'); //校验结果 echo in_array($domain, $Array) ? 'yes' : ''; /* * 客户端代码 */ //获取不带端口号的域名前缀 $servername = trim($_SERVER['SERVER_NAME']); //获取服务端授权文件校验 $verifyurl = file_get_contents('http://www.yunmasucai.com/data/upload/copyright.php?domain='.$servername); if(!empty($verifyurl)){ echo "已授权!"; //授权成功 }else{ die("未授权!"); //授权失败 }
The above is the detailed content of How to add domain name authorization to php source code. For more information, please follow other related articles on the PHP Chinese website!