开发者

htaccess assisting a php file

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 o开发者_运维问答n a .htaccess file because I am feeling abit lazy :)

TIA


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'


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜