Page 1 of 1

Insert code from a file and parse it?

Posted: Thu Jul 24, 2008 4:43 pm
by wrybread
I'm trying to insert a block of code onto every page in a site, and I'd like the code to be parsed. In other words, I'm using the same chunk of PHP code of every page.

Here's how I'm currently inserting the code:

$header = file_get_contents("/home/path/to/code.php");
echo $header;

This successfully inserts the file as text, but it doesn't process the PHP.

Is there a way to insert a block of PHP code from a file onto every page?

Thanks for any help.

Re: Insert code from a file and parse it?

Posted: Thu Jul 24, 2008 6:53 pm
by Eran

Re: Insert code from a file and parse it?

Posted: Thu Jul 24, 2008 9:10 pm
by wrybread
When I do that it still doesn't parse the PHP. I'm doing it like this:

Suppose my file is called test.php and contains:

print "This is a test";

I'm including it like this:

include ("/home/path/to/test.php");

This is inserting the text:

print "This is a test";

Instead of just:

"this is a test".

Am I missing something?

Re: Insert code from a file and parse it?

Posted: Thu Jul 24, 2008 9:15 pm
by wrybread
Oops, got it.

In the included file, you need the php tags.

For example:

<?php

print "test";

?>