Home >Backend Development >PHP Tutorial >How to prevent php templates from being directly stolen? _PHP Tutorial
In many programs, php(as the current mainstream development language) files are used as templates. In this way, php(as the current mainstream development language) language, but the disadvantage is that by directly accessing this file, all the code can be displayed, which brings great convenience to people who steal templates.
In fact, it is very simple to prevent php(as the current mainstream development language) template file from being directly accessed. You only need to add this code to the head of the file:
The following is the code snippet:
$thisfilename = "templates/geek/index.php(As the current mainstream development language)"; //Template file Relative path to be directly accessed if(strtolower(substr($_SERVER["php(as the current mainstream development language)_SELF"],-Len($thisfilename))) == $ thisfilename) exit; ?> |
The code looks very simple, just two sentences, and the principle is also very simple:
Determine the access path of the client. If the direct path to the template file is included, exit the execution.
Because generally template files are placed in a special directory, this path does not need to be accessed directly.
Hope it can bring some help to my friends.
true