Php (as the mainstream development language) files are used as templates in many programs. In this way, php (as the mainstream development language) can be parsed directly in the template, however, the disadvantage is that you can directly access this file to display all the code, which makes template stealing very convenient.
In fact, it is very easy to prevent php (as the mainstream development language) template files from being directly accessed. You only need to add the following code in the file header:
The following is a code snippet: <? Php (as the mainstream development language) $ Thisfilename = "templates/geek/index. php (as the mainstream development language)"; // The relative path to which the template file is directly accessed If (strtolower (substr ($ _ SERVER ["php (as the mainstream development language) _ SELF"],-Len ($ thisfilename) ==$ thisfilename) exit; ?> |
The code looks very simple. The principle of the two statements is also very simple:
Determine the access path of the client. If the direct path of the template file is included, exit the execution.
Generally, we place all template files under a special directory, and this path does not need to be accessed directly.
Hope to help friends.
Never-ending technical exchanges