Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Is it possible to use php includes in pages?
This may seem an odd thing to want to do, but I’m just experimenting with something. I have this in a page:
<txp:php>include ('http://www.napostl.com/php/inc/header.htm'); echo 'hello';</txp:php>
The “hello” is output, but the “header.htm” is not included. Does anyone know why? Is it a security issue? What I’d like to do eventually is connect to a separate, non-TXP database.
Thanks.
Offline
#2 2009-07-01 00:28:47
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: Is it possible to use php includes in pages?
Remove the brackets.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Is it possible to use php includes in pages?
- Why there are PHP code in non-PHP-parsed HTML page? You should parse those (use PHP files, or parse the HTM files) or consider using
eval()
. - You have ini value
allow_url_fopen
set totrue
? - If the file is on same server, don’t use URLs. Use absolute file system paths.
- If you are trying to cross-domain include PHP scripts, you could use secured DBs, and
eval()
for loading the code. But also crossing <?PHP tags kinda works. - If the included thing is just the output, consider using functions that aren’t used to include code, but instead the file’s contents itself. Like
file_get_contents()
.
uli wrote:
Remove the brackets.
No. include()
is a function. It can either be used with brackets or with out. End results are same.
Last edited by Gocom (2009-07-01 00:46:28)
Offline
Re: Is it possible to use php includes in pages?
Gocom wrote:
No.
include()
is a function. It can either be used with brackets or with out. End results are same.
Language construct, punk! :)
Nora – use either an absolute or relative path as recommended by Gocom’s #3.
Offline
Re: Is it possible to use php includes in pages?
Excellent point, Gocom. Not only was I using the html extension instead of php, but I was also referencing variables that wouldn’t exist in my setup – doh! Alas, it’s still not working. Now I have:
<txp:php>include ('/php/inc/footer.php'); echo 'hello';</txp:php>
I checked my php info, and I see the allow_url_fopen
is ON, but allow_url_include
is OFF. Would that be causing the problem? I have non-TXP php pages calling includes with no apparent problem.
The Textpattern install and footer.php are on the same server.
I will look into Gocom’s file_get_contents
recommendation.
Thanks for your help!
Offline
Re: Is it possible to use php includes in pages?
As soon as you removed the scheme (“http://”) from the included file path, allow_url_fopen and allow_url_include became irrelevant.
Are you sure you want the initial forward slash in your file path? That is going to direct PHP to search for your file starting at the server’s root directory – not at the web root.
Offline
Re: Is it possible to use php includes in pages?
Aha! I did not know that about php…makes perfect sense though. I eliminated the initial slash, and it works like a charm (as does including the full path from the server’s root directory).
Thanks everyone!
Offline