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

/home/username/public_html/includefile.php

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

/home/username/public_html/includefile.php

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

includefileatstart.php

<?php

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

?>

includefileatend.php

<?php

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

?>

Create test file:-  test.php

<?php

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

?>
You can download here… http://code.google.com/p/project-php-pretend-append-file/downloads/list

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

<?php
function pa($a,$d=0)
{
error_reporting(E_ALL);
echo “<pre>”;
print_r($a);
echo “</pre>”;
if($d==1) die;
}
?>
Tested like this, test2.php
<?php
$array=array(‘1′,’2′,’3′,’4′,’5′,’6’);

pa($array);

//pa($array,1);

?>

this will o/p the array.

Advertisements

PHP Developer..

Posted in .htaccess, PHP

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: