Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-06-30 23:14:42

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

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

#3 2009-07-01 00:40:00

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Is it possible to use php includes in pages?

  1. 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().
  2. You have ini value allow_url_fopen set to true?
  3. If the file is on same server, don’t use URLs. Use absolute file system paths.
  4. 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.
  5. 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

#4 2009-07-01 02:36:49

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

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

#5 2009-07-01 17:28:55

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

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

#6 2009-07-01 18:46:57

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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

#7 2009-07-01 18:55:56

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

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

Board footer

Powered by FluxBB