Forum Moderators: phranque

Message Too Old, No Replies

Adding code automatically to each loaded page

so I don't have to insert php includes on every page

         

ionchannels

6:57 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



This is my first post at webmaster world. I have just started a free hosting service for my clients and I want to add a php include just under the body of every page:
e.g. <?PHP include("example.inc");?> but I can't expect my clients to insert this snippet on every page. is there a way through Apache to automatically do a regular expression replace or something like that on all files which are loaded from the server? Thanks in advance...

ionchannels

7:48 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



My host just pointed me to an idea...
Use modrewrite to port request page through a php script with the directory/filename as a query string, then use a regular expression replace to insert the php include just below the <body> tag or if it doesn't exist, below </head> etc.. etc... you get the idea... does anyone know any more elegant ways to achieve the same thing?

jdMorgan

9:02 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ionchannels,

Welcome to WebmasterWorld!

That's the hard way to do it, since php has a built-in feature to add footers and/or headers to each page. I can't recall the exact method, but a post over in our PHP forum [webmasterworld.com] will probably get you a quick answer...

Jim

dcrombie

12:45 pm on Jun 10, 2005 (gmt 0)



Using .htaccess you can get PHP to prepend (and maybe 'postpend') a file, but inserting it after the body could be tricky.

[opendeveloper.org...]

Dapuzz

11:48 am on Jun 11, 2005 (gmt 0)

10+ Year Member



auto_prepend is in most common webspace not alowed. You can try, but often a 500 internal server error is displayed. :(