我有很多页面我的问题是我需要打开所有的php文件并在每个php页面的顶部添加一行代码。
<?php
if(!defined('no_d_a')){die('What The ... how did you get here :) ');} /* no direct access */
// rest of existing code here //
?>
问题是我可以在.htaccess文件上执行此操作,因为我感觉abit懒惰:)
TIA
答案 0 :(得分:3)
我认为你想要的是用htaccess预先添加文件的方法吗?如果是这样,你去:
将此保存为'prepend.php'
<?php
if(!defined('no_d_a')){} /* no direct access */
?>
在.htaccess中添加:
<FilesMatch "\.(php)$">
php_value auto_prepend_file "/home/*******/public_html/prepend.php"
</FilesMatch>
它将使用'prepend.php'
预先添加所有.php文件你可能想要一些条件条款..但这应该让你开始..
您还可以使用'auto_append_file'而不是'auto_prepend_file'附加文件
答案 1 :(得分:0)
有一个名为auto_prepend_file
的PHP ini设置,您可以在其中设置将包含在顶部每个PHP脚本中的文件的名称!
您现在可以在.htaccess中设置此设置,如下所示:
php_value auto_prepend_file prepend.php