htaccess assisting a php file

2019-09-01 05:51发布

I have many pages my problem stands that I need to open all my php files and add a line of code at the top of each php page.

<?php 
if(!defined('no_d_a')){die('What The ... how did you get here :) ');} /* no direct access */ 
// rest of existing code here //
?>

Question is can I instead do this on a .htaccess file because I am feeling abit lazy :)

TIA

标签: php .htaccess
2条回答
Viruses.
2楼-- · 2019-09-01 06:15

There is a PHP ini setting called: auto_prepend_file, where you can set the name of a file wich will be included into every PHP script at the top!

You can now set this setting in your .htaccess like this:

php_value auto_prepend_file prepend.php

Check this good tutorial

查看更多
趁早两清
3楼-- · 2019-09-01 06:28

I think what your wanting is a way to prepend the files with htaccess? If so here ya go:

Save this as 'prepend.php'

<?php
  if(!defined('no_d_a')){} /* no direct access */ 
?> 

in your .htaccess add:

<FilesMatch "\.(php)$">
php_value auto_prepend_file "/home/*******/public_html/prepend.php"
</FilesMatch>

it will prepend all .php files with 'prepend.php'

You may want to have some conditional clauses.. but that should get you started..


You can also append files with 'auto_append_file' instead of 'auto_prepend_file'

查看更多
登录 后发表回答