Does the PHP require function output when it encounters text?
This is the template class I wrote:
/** * User: Fire lizard making */namespace core;//template class template{private $data = []; Private $path = '; Template path Public function __construct () {$this->path = config::get (' Project.template_path '); /** * Template Assignment * @param $key * @param $value */Public Function assign ($key, $value) {if (Is_ar Ray ($key)) {$this->data = Array_merge ($this->data, $key); } else {$this->data[$key] = $value; }}/** * Gets the path * @param $file */Private Function GetFilePath ($file) {$params = explode ('. '), $file); The template path has been delimited $path = ROOT. Directory_separator. $this->path; foreach ($params as $key = + $param) {if ($key = = count ($params)-1) {$path. = $param; } else {$path. = $param. Directory_separator; }} return $path. '. html '; Public function display ($file) {if (Empty ($file){throw new \exception ("Template Can not is Empty"); } $realPath = $this->getfilepath ($file); if (Is_file ($realPath)) {Extract ($this->data); Require ($realPath); } else {throw new \exception ("Template:{$realPath}
Not Found "); } }}
Reply content:
Does the PHP require function output when it encounters text?
This is the template class I wrote:
/** * User: Fire lizard making */namespace core;//template class template{private $data = []; Private $path = '; Template path Public function __construct () {$this->path = config::get (' Project.template_path '); /** * Template Assignment * @param $key * @param $value */Public Function assign ($key, $value) {if (Is_ar Ray ($key)) {$this->data = Array_merge ($this->data, $key); } else {$this->data[$key] = $value; }}/** * Gets the path * @param $file */Private Function GetFilePath ($file) {$params = explode ('. '), $file); The template path has been delimited $path = ROOT. Directory_separator. $this->path; foreach ($params as $key = + $param) {if ($key = = count ($params)-1) {$path. = $param; } else {$path. = $param. Directory_separator; }} return $path. '. html '; Public function display ($file) {if (Empty ($file){throw new \exception ("Template Can not is Empty"); } $realPath = $this->getfilepath ($file); if (Is_file ($realPath)) {Extract ($this->data); Require ($realPath); } else {throw new \exception ("Template:{$realPath}
Not Found "); } }}
require
Not a function
require
The function is to put the following string as the file name, regardless of the file extension is not .php
, all think that the file is a PHP program, introduced into the current program run.
If the PHP program is not 和?>
包起来,就会直接输出。
require
executes the referenced file as a PHP file, regardless of the suffix name of the file (no suffix is allowed), and some PHP Trojans use this to bypass firewalls. The
PHP code needs to be placed in the !--? php and .
to execute.
Crab Demon.
When a file is included, the parser goes out of PHP mode at the beginning of the target file and enters HTML mode to recover at the end of the file. For this reason, any code in the destination file that needs to be executed as PHP code must be included in the valid PHP start and end tags.
include
or requrie
a file without PHP start and end tags !--? php?-->
are parsed as HTML.