elsombreron Posted April 3, 2009 Share Posted April 3, 2009 I'm kind of self-taught here, so apologies if this is stupid or simple. I have a couple of php files that have some content that gets repeated throughout all my site's pages, so to save me having to replicate the content every time, I have readfile() call the base content when I need it. So I have something like this: ---Start base file called base.php (5 lines as an example)---- <? //some PHP code here $img_source="path/to/somewhere"; ?> <h1>Some header</h1> ---End base file called base.php---- ---Start new file called newfile.php---- <? readfile(base.php); ?> <img src="<?php echo($img_source);?>"> ---End base file called newfile.php---- In the newfile.php file, the readfile(base.php) works, because I can see the resulting source code to be this: -------Resulting code when newfile.php is loaded------ <h1>Some header</h1> <img src=""> ------------------------------------------------------------ I can see that the header HTML code was pulled in from base.php, but I can also see that the variable $img_source, which was defined in base.php but called in newfile.php isn't recognized (see the empty src="" bit)! I'm scratching my head here since I thought readfile() was essentially just copying and pasting base.php's contents into newfile.php, but something is going on with the PHP that I've written that I'm missing, obviously. Any pointers would be more than appreciated, I've spent ages on this and still can't figure it out! Many thanks. Link to comment https://forums.phpfreaks.com/topic/152341-readfile-help/ Share on other sites More sharing options...
monokrome Posted April 3, 2009 Share Posted April 3, 2009 readfile() isn't going to parse your text as PHP... You are looking for require() or include(), most likely. Link to comment https://forums.phpfreaks.com/topic/152341-readfile-help/#findComment-800066 Share on other sites More sharing options...
elsombreron Posted April 3, 2009 Author Share Posted April 3, 2009 Thanks monokrome! I tried require() and include() but these have been disabled by the server. From reading around, I think a lot of people prefer to not use require or include for security reasons. Any other simple way around this other than enabling require() or include()? Link to comment https://forums.phpfreaks.com/topic/152341-readfile-help/#findComment-800074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.