如何从另一个PHP脚本执行一个PHP脚本?

Ngu*_*yen 3 php security shell exec

我有一些名为file1.php、file2.php、file3.php的 PHP 文件。现在,我想从另一个名为all.php的 PHP 文件中一一运行这些 PHP 文件。我的意思是 file2.php 将在 file1.php 完成后执行。file3.php将在file2.php完成后执行。怎么做 ?

我可以使用 exec 函数吗?我的托管安全吗?我在共享主机中使用 Cpanel。有什么办法可以做到这一点,但对我的托管内容来说是安全的?

非常感谢 !

Ron*_*ser 5

你可以使用include()

include('file1.php');
include('file2.php');
include('file3.php');
Run Code Online (Sandbox Code Playgroud)

include_once()

include_once('file1.php');
include_once('file2.php');
include_once('file3.php');
Run Code Online (Sandbox Code Playgroud)

requirerequire_once

require 'file1.php';
require 'file2.php';
require 'file3.php';
Run Code Online (Sandbox Code Playgroud)

=>require()将产生致命错误 (E_COMPILE_ERROR) 并停止脚本

=> include()只会产生警告 (E_WARNING) 并且脚本将继续