Forum Moderators: phranque

Message Too Old, No Replies

include on every page

best way

         

WhosAWhata

1:34 am on May 12, 2004 (gmt 0)

10+ Year Member



if i want to include a header and a footer on every page (or run a function is_user_valid($user,$pass) on every page)

would the best way be to
include("header.php");
#other stuff
include("footer.php");
on every page (totally php code)

or to have a file like
<?
#return.php
#header stuff
if(file_exists($file)) include($file);
#footer stuff
?>

and then add a .htaccess that looked like this


[pre]RewriteEngine on
RewriteCond %{REQUEST_URI}!^return.php
RewriteCond %{REQUEST_URI} -f
RewriteRule (.*) return.php?file=$1[/pre]

both of these ways will work, but the second seems easier
has anyone experimented with these techniques?
ideas? recomendations?

WhosAWhata

6:19 pm on May 15, 2004 (gmt 0)

10+ Year Member



really what i'm curiuos about is the second way
has anyone used this method? how does it work for you? any issues or problems?

gergoe

7:22 pm on May 15, 2004 (gmt 0)

10+ Year Member



Personally I didn't use this solution, but I see no problems with it. The only drawback might be that you can't define different header/footer not for one page, unless you change your rewriting, but that's not a big deal actually.
The only problem I found using automated generation of the header (footer) is when I used some html forms in the header (for general search on the website), then I found difficult to use javascript to check the content of a form in the included pages (I prefer the document.forms[#] method to refer to a form, but if I have a form in the header already then the forms collection will be different as it can be expected).
Just go on, and if you find it difficult or troublesome, then you can look for another solution.

By the way, why you are checking the existence of the file from php if you have it checked by the apache previously?

WhosAWhata

8:56 pm on May 15, 2004 (gmt 0)

10+ Year Member



in case someone discovers my layout and trys to access return.php?file=SomePageThatDoesNotExist.php

coopster

2:06 pm on May 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another consideration (when using PHP) is auto_prepend_file [php.net] and auto_append_file [php.net] .