Two Methods of Domain Name Authorization in PHP

web front end thirteen thousand one hundred and thirty-two 7 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(' '.$ 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('','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",""); //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.