Home  >  Article  >  Backend Development  >  Say goodbye to hotlinks..._PHP Tutorial

Say goodbye to hotlinks..._PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:10:001026browse


Randomly generate a number (0-15) on the first page - "dechex() and save it in the session

Then use this tag to perform calculations on the URL. You can do the calculation as you wish, but it must be reversed. ~

The second page detects whether there is this mark, if so, performs the inverse operation, and then takes out the variable

Advantages: (Must visit the site URL to be valid~)

Disadvantages: (All links saved to local pages are invalid, hotlinks are invalid)

------------------------------ ------------------

ob_start();
session_start();
if(isset($_SESSION [key])){ //Have a key

$key=$_SESSION[key]; //Get the key
$str=$_SERVER[QUERY_STRING]; //Get the encrypted data
$decryptstr=decrypt($str,$key); //Use the key to unlock the data (note, this is your inverse algorithm)
............. ............//(Decompose data into variables)
}else{                                                                                                                                                                                                                                                                             ; /Generate key
//If your page is already the last page and hotlinking is not allowed
//echo "Your link does not come from this site! Please visit the site and then visit this page.. .";
//exit();
}
?>
HTML content............(This contains many links... )

$htmlcontent=ob_get_contents(); //Get all HTML content
........................ ...........                            // Replace all connection parameters href=url?Replaced data (a set of regular)
ob_end_flush(); )
?>

http://www.bkjia.com/PHPjc/314318.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314318.htmlTechArticleRandomly generate a number (0-15) on the first page -> dechex() save it in the session and then Use this tag to perform calculations on the URL. You can do the calculation as you wish, but you must be able to reverse it~ The second page is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn