Home >Backend Development >PHP Tutorial >How to prevent php templates from being directly stolen? _PHP Tutorial

How to prevent php templates from being directly stolen? _PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:30:45961browse

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(做为现在的主流开发语言)"; //模版文件被直接访问的相对路径
if(strtolower(substr($_SERVER["php(做为现在的主流开发语言)_SELF"],-Len($thisfilename))) == $thisfilename) exit;
?>
(As the current mainstream development language)

$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.

Technical exchanges never end http://www.bkjia.com/PHPjc/509164.htmlwww.bkjia.com
true
http: //www.bkjia.com/PHPjc/509164.html
TechArticleIn many programs, php (as the current mainstream development language) files are used as templates. This can Parse the php (as the current mainstream development language) language directly in the template, but also...
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