Include php file On all the pages of php

I need to include a files in all of your site’s pages? Normally, you’d use require() or include(). But do I really want to manually past the include code in every page?

This may be at the start of page or end of page.

There’s the little known PHP directive auto_prepend_file and auto_append_file. What are PHP directives? They’re essential global PHP settings that are defined in you php.ini file. There is surprisingly little information about these methods out there, but luckily they aren’t too difficult to work with.

In the php.ini file, we can implement like this,

; Automatically add files before or after any PHP document.
auto_prepend_file = D:/wamp/www/includefileatstart.php
auto_append_file =  D:/wamp/www/includefileatend.php

For Linux system it is something like this


For me this will not work on Wamp…  😉

So I have to find another way, … so we did with the help of .htaccess.. we can set it at runtime…

Create .htaccess file in www folder.

php_value auto_prepend_file D:/wamp/www/includefileatstart.php
php_value auto_append_file D:/wamp/www/includefileatend.php

For Linux system it is something like this


Create file the file which you want to include  ‘includefileatstart.php’ and ‘includefileatend.php’



echo “included at the start of program <br />”;




echo “included at the end of program<br />”;


Create test file:-  test.php


echo “this is body of page<br>”;

You can download here…

I have created function file & this is included at the start.
Like this :- includefunction.php

function pa($a,$d=0)
echo “<pre>”;
echo “</pre>”;
if($d==1) die;
Tested like this, test2.php




this will o/p the array.

Posted in .htaccess, PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: