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.
Insert code from a file and parse it?
Moderator: General Moderators
Re: Insert code from a file and parse it?
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?
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?
Oops, got it.
In the included file, you need the php tags.
For example:
<?php
print "test";
?>
In the included file, you need the php tags.
For example:
<?php
print "test";
?>