Two Methods of Domain Name Authorization in PHP

web front end fifteen thousand three hundred and ninety-six 8 years ago (2016-09-18)

01.  Method of online verification of domain name authorization

Client code:

 <? php //Get the domain name prefix without port number $servername = trim($_SERVER['SERVER_NAME']); //Get the server authorization file verification $verifyurl = file_get_contents(' https://www.toyean.com/zb_users/upload/copyright.php?domain= '.$ servername); if(!empty($verifyurl)){ Echo "Authorized!"; //Authorization succeeded }else{ Die ("Unauthorized!"); //Authorization failed } ?>

Server code:

 <? php //Get domain name $domain = $_GET['domain']; //List of authorized domain names $Array = array('127.0.0.1','localhost'); //Verification results echo in_array($domain, $Array) ?  'yes' : ''; ?>

The domain name authorization code can be encapsulated into a function or encrypted. For common PHP encryption forms, there are methods to crack them, such as ZendGuard, ionCube, etc. If there are many authorized domain names, you can add a domain name field in the project and write the domain name data base Then read and verify. This method has been released as an independent plug-in unit , see: ZBlogPHP domain name authorization plug-in - AllowURL The domain name and other information can be added to the database for verification through plug-ins.


two Method of independently verifying domain name authorization

 <? php function allow_domain(){ $is_allow=false; //Get the domain name prefix without port number $servername=trim($_SERVER['SERVER_NAME']); //List of authorized domain names $Array=array("localhost","127.0.0.1"); //Traversal array foreach($Array as $value){ $value=trim($value); $domain=explode($value,$servername); if(count($domain)>1){ $is_allow=true; break; } } if(!$is_allow){ Die ("Domain name is not authorized!"); //Authorization failed }else{ Echo "The domain name is authorized!"; //Authorization succeeded } } allow_domain(); ?>

The purpose of domain name authorization is to protect intellectual property rights, encourage developers to publish more excellent works, and promote the whole network Sociology The cultural development and scientific and technological progress are of great significance.