By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

php include design question

P: n/a
so, i'm making a website. let's say i have header.php, footer.php and
content.php.

now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?

i suppose i can include a variable in header.php that basically says
"i've been included", and then in content.php if this variable isn't
set, i could include them... is this the best/most elegant approach?
Aug 13 '08 #1
Share this Question
Share on Google+
25 Replies


P: n/a

"Mark" <mn*******@gmail.comha scritto nel messaggio
news:3a**********************************@p31g2000 prf.googlegroups.com...
so, i'm making a website. let's say i have header.php, footer.php and
content.php.

now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?

i suppose i can include a variable in header.php that basically says
"i've been included", and then in content.php if this variable isn't
set, i could include them... is this the best/most elegant approach?


example
--index.php--
<?php
define('is_inc',true);
readfile('header.php');
include('content.php');
readfile('footer.php');
?>

--content.php--
<?php
if(!defined('is_inc')){exit();}
echo 'mycontent';
?>
---------------------

Yes the variable or define methods are the most used.

Regards

L. A. Iarrusso
Aug 14 '08 #2

P: n/a
On Aug 13, 6:31*pm, "J2Be.com" <mym...@virgilio.itwrote:
"Mark" <mnbaya...@gmail.comha scritto nel messaggionews:3a********************************** @p31g2000prf.googlegroups.com...
so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
i suppose i can include a variable in header.php that basically says
"i've been included", and then in content.php if this variable isn't
set, i could include them... is this the best/most elegant approach?

example
--index.php--
<?php
define('is_inc',true);
readfile('header.php');
include('content.php');
readfile('footer.php');
?>

--content.php--
<?php
if(!defined('is_inc')){exit();}
echo 'mycontent';
?>
---------------------

Yes the variable or define methods are the most used.

Regards

L. A. Iarrusso
In your scenario accessing content.php directly outputs nothing?

I had more of this in mind:

--header.php--
define('header_inc',true);
// header stuffs

--content.php--
if(!defined('header_inc')) include 'header.php';
echo 'mycontent';
if(!defined('footer_inc')) include 'footer.php';

--index.php--
include 'header.php';
include 'content.php';
include 'footer.php';
Of course, this pretty much makes index.php and content.php identical,
but the idea was that after the header and footer are loaded once, I
could use ajax to sub in different content pages instead of reloading
the whole page...

But thinking about this more...that wouldn't work. If I used ajax to
include the new content, header_inc wouldn't be defined and I'd wind
up with 2 headers and footers.

I guess what I'd have to do is include a variable in the URL in my
ajax call?

Basically...

--content.php--
if(!isset('dont_load')) include 'header.php';
// content
if(!isset('dont_load')) include 'footer.php';

And then when I sub a page in w/ ajax I just call it with content.php?
dont_load=1

That should work right? Sorry I wasn't more clear the first time.
Aug 14 '08 #3

P: n/a
NC
On Aug 13, 4:41 pm, Mark <mnbaya...@gmail.comwrote:
>
so, i'm making a website. let's say i have header.php,
footer.php and content.php.

i suppose i can include a variable in header.php that
basically says "i've been included", and then in content.php
if this variable isn't set, i could include them... is this
the best/most elegant approach?
Elegance is in the eye of the beholder, so I can't really say whether
or not this is the most elegant approach. There is, however, an
alternative. You can put header.php, footer.php and content.php into
a subdirectory and disable HTTP access to it with .htaccess.

This approach allows for easy theming. Say, right now you have:

$themeName = 'default';
$themeDir = 'themes/' . $themeDir;
include "$themeDir/header.php";
include "$themeDir/content.php";
include "$themeDir/footer.php";

Then you can work out a new set of content display files, put them
into a different directory, say, themes/new, and switch the new theme
on by changing a single line (the value of $themeName) in index.php...

Cheers,
NC
Aug 14 '08 #4

P: n/a
Mark wrote:
--content.php--
if(!isset('dont_load')) include 'header.php';
// content
if(!isset('dont_load')) include 'footer.php';

And then when I sub a page in w/ ajax I just call it with content.php?
dont_load=1

That should work right? Sorry I wasn't more clear the first time.
I think you are patching one bad choice with another but I dont really
have the time to explain.
Why dont you have a look at the larger framworks and see how they have
done it.

Floortje

Aug 14 '08 #5

P: n/a
..oO(Mark)
>so, i'm making a website. let's say i have header.php, footer.php and
content.php.

now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.

Micha
Aug 14 '08 #6

P: n/a
On Aug 14, 10:30*am, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?

Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.

Micha
Well, how else are people going to bookmark a particular page, or link
it to their friends? If I don't make it accessible somehow, the only
way people will be able to get to it is by going through the index.
Aug 14 '08 #7

P: n/a
On Aug 13, 11:58*pm, Floortje <floor...@dontlike.mailwrote:
Mark wrote:

* --content.php--
if(!isset('dont_load')) include 'header.php';
// content
if(!isset('dont_load')) include 'footer.php';
And then when I sub a page in w/ ajax I just call it with content.php?
dont_load=1
That should work right? Sorry I wasn't more clear the first time.

I think you are patching one bad choice with another but I dont really
have the time to explain.
Why dont you have a look at the larger framworks and see how they have
done it.

Floortje
Which frameworks? The only other site that I've seen doing this is
deviantART. It seems to use AJAX to load the main content and sidebar
separately, but gracefully downgrades if you disable JavaScript.

That means that you need a file containing just the bare content so
that you can load it into the page when navigating through the
sidebar, but it needs to load the entire page when you access it
directly... unless you have two copies of every page, one with the
header and footer and one without, but that sounds terrible.

If you could point me to some frameworks that do this, it would be
much appreciated. I don't even know what to search for.
Aug 14 '08 #8

P: n/a
On Aug 13, 11:12*pm, NC <n...@iname.comwrote:
On Aug 13, 4:41 pm, Mark <mnbaya...@gmail.comwrote:
so, i'm making a website. let's say i have header.php,
footer.php and content.php.
i suppose i can include a variable in header.php that
basically says "i've been included", and then in content.php
if this variable isn't set, i could include them... is this
the best/most elegant approach?

Elegance is in the eye of the beholder, so I can't really say whether
or not this is the most elegant approach. *There is, however, an
alternative. *You can put header.php, footer.php and content.php into
a subdirectory and disable HTTP access to it with .htaccess.

This approach allows for easy theming. *Say, right now you have:

$themeName = 'default';
$themeDir = 'themes/' . $themeDir;
include "$themeDir/header.php";
include "$themeDir/content.php";
include "$themeDir/footer.php";

Then you can work out a new set of content display files, put them
into a different directory, say, themes/new, and switch the new theme
on by changing a single line (the value of $themeName) in index.php...

Cheers,
NC
I forgot about the applications of theming :) I was thinking about
doing themes for my site, but I was just going to have different style
sheets....but including the header and footer would give me way more
flexibility. Thanks for the idea!
Aug 14 '08 #9

P: n/a
..oO(Mark)
>On Aug 14, 10:30*am, Michael Fesser <neti...@gmx.dewrote:
>.oO(Mark)
>so, i'm making a website. let's say i have header.php, footer.php and
content.php.
>now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?

Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.

Micha

Well, how else are people going to bookmark a particular page, or link
it to their friends? If I don't make it accessible somehow, the only
way people will be able to get to it is by going through the index.
It's still not exactly clear what you want. If the content.php just
contains the content of a single page, then it should not be directly
callable, as said. But if it's an entire page instead, then there's no
point in including it in the index.php ... what am I missing?

Usually it's like this: You have a bunch of pages, and each page simply
includes the header.php and footer.php (I would rather name them *.inc,
but that's just personal preference). Of course these page scripts have
to be publically available, but not the included header and footer files
because they are not meant to be called directly.

Micha
Aug 14 '08 #10

P: n/a
On 14 Aug, 20:10, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)


On Aug 14, 10:30*am, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.
Micha
Well, how else are people going to bookmark a particular page, or link
it to their friends? If I don't make it accessible somehow, the only
way people will be able to get to it is by going through the index.

It's still not exactly clear what you want. If the content.php just
contains the content of a single page, then it should not be directly
callable, as said. But if it's an entire page instead, then there's no
point in including it in the index.php ... what am I missing?

Usually it's like this: You have a bunch of pages, and each page simply
includes the header.php and footer.php (I would rather name them *.inc,
but that's just personal preference). Of course these page scripts have
to be publically available, but not the included header and footer files
because they are not meant to be called directly.

Micha- Hide quoted text -

- Show quoted text -
Of course the problem with calling them *.inc is that anyone calling
it from their browser will see any php code within them.
Aug 14 '08 #11

P: n/a
..oO(Captain Paralytic)
>Of course the problem with calling them *.inc is that anyone calling
it from their browser will see any php code within them.
In the worst case the same can happen with *.php and as I've already
said twice in this thread - such files don't belong to the document
root. Put them one level higher: no URL, no problem.

Micha
Aug 14 '08 #12

P: n/a
Mark wrote:
On Aug 14, 10:30 am, Michael Fesser <neti...@gmx.dewrote:
>.oO(Mark)
>>so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.

Micha

Well, how else are people going to bookmark a particular page, or link
it to their friends? If I don't make it accessible somehow, the only
way people will be able to get to it is by going through the index.
Don't confuse the file with the page. You can store a file outside of
the document root and still include it in a page.

But if index.php includes is the only page ever called, how are you
going to determine which file to include for your content?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 14 '08 #13

P: n/a
On 14 Aug, 20:57, Michael Fesser <neti...@gmx.dewrote:
.oO(Captain Paralytic)
Of course the problem with calling them *.inc is that anyone calling
it from their browser will see any php code within them.

In the worst case the same can happen with *.php and as I've already
said twice in this thread
Not that I can see you haven't. Whilst it is true that if the server
breaks it is possible that php code can be sent to the browser un-
interpreted, it will be a very very rare ocurence. However not many
servers are set up to send .inc files to the php interpreter and thus
those files are far more likely to display the code.
- such files don't belong to the document
root. Put them one level higher: no URL, no problem.
But you did not say this in the post where you advised calling them
*.inc
If you want to put inc in the name *.inc.php is safer.
>
Micha
Aug 14 '08 #14

P: n/a
..oO(Captain Paralytic)
>On 14 Aug, 20:57, Michael Fesser <neti...@gmx.dewrote:
>.oO(Captain Paralytic)
>Of course the problem with calling them *.inc is that anyone calling
it from their browser will see any php code within them.

In the worst case the same can happen with *.php and as I've already
said twice in this thread
Not that I can see you haven't. Whilst it is true that if the server
breaks it is possible that php code can be sent to the browser un-
interpreted, it will be a very very rare ocurence. However not many
servers are set up to send .inc files to the php interpreter and thus
those files are far more likely to display the code.
Servers don't have to be setup to parse *.inc files for anything simply
because such files are not meant to be accessible. That's the whole
point. If you can reach such a file by URL, you've made a mistake and
an improper directory structure.
>>- such files don't belong to the document
root. Put them one level higher: no URL, no problem.
But you did not say this in the post where you advised calling them
*.inc
I mentioned it in my first reply and referred to that in my second.
>If you want to put inc in the name *.inc.php is safer.
Yes, if the files are stored in the wrong place. Then you have to solve
a problem made by yourself. But if the files would be stored where they
belong, then you wouldn't have this problem at all and could name them
any way you want.

Micha
Aug 14 '08 #15

P: n/a
Mark wrote:
Which frameworks? The only other site that I've seen doing this is
deviantART. It seems to use AJAX to load the main content and sidebar
separately, but gracefully downgrades if you disable JavaScript.

That means that you need a file containing just the bare content so
that you can load it into the page when navigating through the
sidebar, but it needs to load the entire page when you access it
directly... unless you have two copies of every page, one with the
header and footer and one without, but that sounds terrible.

If you could point me to some frameworks that do this, it would be
much appreciated. I don't even know what to search for.
ZEND CakePHP symfony Codeigniter PRADO for example but really anything
will do. Any simple cms will also have this option ot atleast a plugin
to make this happen.
Aug 15 '08 #16

P: n/a
On Aug 14, 12:10*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
On Aug 14, 10:30*am, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
Why do you want the content.php to be callable? Includes should be
stored outside the document root, so that they can't be reached by a
URL. Then you won't have this problem at all.
Micha
Well, how else are people going to bookmark a particular page, or link
it to their friends? If I don't make it accessible somehow, the only
way people will be able to get to it is by going through the index.

It's still not exactly clear what you want. If the content.php just
contains the content of a single page, then it should not be directly
callable, as said. But if it's an entire page instead, then there's no
point in including it in the index.php ... what am I missing?
Micha
I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.

Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax. Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).

Anyway, I did manage to find a way to do this by passing a parameter
through ajax which tells it if it should be "bare" or "full". Except I
ran into some issues where it wouldn't always load the page... so I'm
sticking with a non-ajax site for now...

There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.
Aug 19 '08 #17

P: n/a
Mark wrote:
I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.

Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax. Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).
Why not simply have:
header.php
footer.php
inside1.php
inside2.php

index.php = header.php + inside1.php + footer.php (via includes)
content2.php = header.php + inside2.php + footer.php (via includes)

Why do you even need AJAX for this?

I like a design that has something like this for page foo.php:

<?php
include 'php_header.php'; // Has things like session_start(), etc.
$title = 'This is page foo";
include 'foo_process.php';
$html_include = 'foo_html.php';
include 'template.php';
?>

and then I would have in template.php all the basic html stuff, with an
include of header.inc.php and footer.inc.php and in the content area I have
<?php include $html_include; ?>

That gives the same presentation over all pages and separates the page
processing and page content presentation into two files which are
included. All files for a page are tied together by the name "foo" and
the page is callable as mysite.com/foo.php. To handle the form submit,
I could either have it done in foo_process.php, or have a separate file
foo_submit.php. Either way works. The point is that with this kind of
arrangement you have consistency, yet have independent callable pages.
Aug 20 '08 #18

P: n/a
..oO(Mark)
>I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.

Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax.
Bad idea for at least two reasons:

1) It requires JavaScript, which is not always available.
2) The browser's address bar won't reflect the change, hence it would be
impossible to bookmark these pages.
>Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).
Drop the entire AJAX idea, you don't really need it. In fact AJAX may
cause severe usability and accessibility problems if not used properly.
Instead build simple, flat pages, which include the header and footer.
It's easy, reliable and efficient.
>There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.
You're trying to over-optimize and will cause new problems with that
approach. There's nothing wrong with reloading header and footer on
every page. Images (if there are any) are cached and some KB of HTML
don't really matter. One URL, one document. It's that easy.

Micha
Aug 21 '08 #19

P: n/a
AqD
For files with only functions and classes (no html output), you could
just use require_once().
For html output ones, I strongly suggest you to choose one uniform
style: either use the index.php to include header/footer and
content.php and all other contents (act as the central dispatcher), or
each of the user-reachable php files includes header/footer manually
by require() - which is simple but requires code duplication.

On Aug 14, 7:41*am, Mark <mnbaya...@gmail.comwrote:
so, i'm making a website. let's say i have header.php, footer.php and
content.php.

now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?

i suppose i can include a variable in header.php that basically says
"i've been included", and then in content.php if this variable isn't
set, i could include them... is this the best/most elegant approach?
Aug 22 '08 #20

P: n/a
On Aug 21, 12:28*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.
Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax.

Bad idea for at least two reasons:

1) It requires JavaScript, which is not always available.
2) The browser's address bar won't reflect the change, hence it would be
* *impossible to bookmark these pages.
Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).

Drop the entire AJAX idea, you don't really need it. In fact AJAX may
cause severe usability and accessibility problems if not used properly.
Instead build simple, flat pages, which include the header and footer.
It's easy, reliable and efficient.
There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.

You're trying to over-optimize and will cause new problems with that
approach. There's nothing wrong with reloading header and footer on
every page. Images (if there are any) are cached and some KB of HTML
don't really matter. One URL, one document. It's that easy.

Micha
1. That's the second reason it should be directly callable. It
downgrades nicely. It will work both with and without Javascript. With
Javascript enabled, it doesn't need to reload the headers and footers,
without JS, it does.
2. Actually, it will. It'll just contain a hash # symbol in the URL,
ie, mysite.com/#mypage. I can also inject the page into the history so
that the back, forward and bookmark buttons work.

In fact, I got the whole thing working exactly like I've said, but on
occasion Ajax would refuse to load a page. And I can't exactly have
that sort of instability...

Anyway, I guess you're right about the over-optimizing. I've scratched
the Ajax stuff altogether. I'll look at it again in the future if it
becomes a problem. Gmail and other sites (like DeviantART) do
something like what I was mentioning, so there must be a benefit to
it, and it's definitely do-able.

Thanks.
Mark
Sep 3 '08 #21

P: n/a
On Aug 22, 6:32*am, AqD <aquila.d...@gmail.comwrote:
For files with only functions and classes (no html output), you could
just use require_once().
For html output ones, I strongly suggest you to choose one uniform
style: either use the index.php to include header/footer and
content.php and all other contents (act as the central dispatcher), or
each of the user-reachable php files includes header/footer manually
by require() - which is simple but requires code duplication.

On Aug 14, 7:41*am, Mark <mnbaya...@gmail.comwrote:
so, i'm making a website. let's say i have header.php, footer.php and
content.php.
now in index.php I simply want to include the 3 pages. easy enough to
do.
but let's say the user navigates to mysite.com/content.php. now the
header and footer will appear to be missing.
so now the question is, how can i include the header and footer in
content.php only if the page isn't already nested?
i suppose i can include a variable in header.php that basically says
"i've been included", and then in content.php if this variable isn't
set, i could include them... is this the best/most elegant approach?
Unfortunately the circumstances force me to use a non-uniform style,
otherwise I'd happily stick with one.

Mark
Sep 3 '08 #22

P: n/a
On Aug 20, 4:32*am, sheldonlg <sheldonlgwrote:
Mark wrote:
I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.
Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax. Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).

Why not simply have:
header.php
footer.php
inside1.php
inside2.php

index.php = header.php + inside1.php + footer.php *(via includes)
content2.php = header.php + inside2.php + footer.php (via includes)

Why do you even need AJAX for this?

I like a design that has something like this for page foo.php:

<?php
include 'php_header.php'; *// Has things like session_start(), etc.
$title = 'This is page foo";
include 'foo_process.php';
$html_include = 'foo_html.php';
include 'template.php';
?>

and then I would have in template.php all the basic html stuff, with an
include of header.inc.php and footer.inc.php and in the content area I have
<?php include $html_include; ?>

That gives the same presentation over all pages and separates the page
processing and page content presentation into two files which are
included. *All files for a page are tied together by the name "foo" and
the page is callable as mysite.com/foo.php. *To handle the form submit,
I could either have it done in foo_process.php, or have a separate file
foo_submit.php. *Either way works. *The point is that with this kind of
arrangement you have consistency, yet have independent callable pages.
I don't *need* Ajax, it's simply an efficiency thing. And I detest the
idea of having parallel files like that, but thanks for the suggestion
anyway. When I'm not using Ajax, I normally use a similar approach. I
try to be consistent where possible.

Mark
Sep 3 '08 #23

P: n/a
Mark wrote:
On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.dewrote:
>.oO(Mark)
>>I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.
Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax.
Bad idea for at least two reasons:

1) It requires JavaScript, which is not always available.
2) The browser's address bar won't reflect the change, hence it would be
impossible to bookmark these pages.
>>Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).
Drop the entire AJAX idea, you don't really need it. In fact AJAX may
cause severe usability and accessibility problems if not used properly.
Instead build simple, flat pages, which include the header and footer.
It's easy, reliable and efficient.
>>There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.
You're trying to over-optimize and will cause new problems with that
approach. There's nothing wrong with reloading header and footer on
every page. Images (if there are any) are cached and some KB of HTML
don't really matter. One URL, one document. It's that easy.
<snip>
Anyway, I guess you're right about the over-optimizing. I've scratched
the Ajax stuff altogether. I'll look at it again in the future if it
becomes a problem. Gmail and other sites (like DeviantART) do
something like what I was mentioning, so there must be a benefit to
it, and it's definitely do-able.
Their reasoning isn't necessarily optimization, it's to enhance the
web UI for the users, and make interacting more intuitive. However, in
Gmail, the user always has the option of using the standard HTML
interface.

If you're turning to "Ajax" to optimize things, you're either
optimizing prematurely, or not looking at the right places for dealing
with bottlenecks.

--
Curtis
Sep 4 '08 #24

P: n/a
On Sep 4, 2:10*am, Curtis <dye...@gmail.comwrote:
Mark wrote:
On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
>I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.
Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax.
Bad idea for at least two reasons:
1) It requires JavaScript, which is not always available.
2) The browser's address bar won't reflect the change, hence it would be
* *impossible to bookmark these pages.
>Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).
Drop the entire AJAX idea, you don't really need it. In fact AJAX may
cause severe usability and accessibility problems if not used properly..
Instead build simple, flat pages, which include the header and footer.
It's easy, reliable and efficient.
>There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.
You're trying to over-optimize and will cause new problems with that
approach. There's nothing wrong with reloading header and footer on
every page. Images (if there are any) are cached and some KB of HTML
don't really matter. One URL, one document. It's that easy.

<snip>
*Anyway, I guess you're right about the over-optimizing. I've scratched
the Ajax stuff altogether. I'll look at it again in the future if it
becomes a problem. Gmail and other sites (like DeviantART) do
something like what I was mentioning, so there must be a benefit to
it, and it's definitely do-able.

Their reasoning isn't necessarily optimization, it's to enhance the
web UI for the users, and make interacting more intuitive. However, in
Gmail, the user always has the option of using the standard HTML
interface.

If you're turning to "Ajax" to optimize things, you're either
optimizing prematurely, or not looking at the right places for dealing
with bottlenecks.

--
Curtis
Actually, there was one other reason I wanted to use Ajax. I wanted
the menu and the main content to load separately from eachother. I'm
going to have a tree menu, that expands as you click on it. I don't
want to refresh the page the entire page every time a user clicks
something. Yes, I could use *just* javascript for that, but I suspect
there will be hundreds, or even thousands of entries one day, so I
don't necessarily want to load the whole thing at once. And when a
user clicks a category, the main page should show a more detailed
listing...but the idea is that the user doesn't have to wait for it to
load if he doesn't want to. Anyway, not a big deal just yet.

Mark
Sep 7 '08 #25

P: n/a
Mark wrote:
On Sep 4, 2:10 am, Curtis <dye...@gmail.comwrote:
>Mark wrote:
>>On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(Mark)
I want it to be directly callable so that people can link their
friends to it. I just want to make sure its properly nested between
the header and footer at all times; whether it's inserted via ajax, or
whether its called directly.
Let's say that in index.php I include header.php, content.php and
footer.php. Then, a user clicks a link on the page. I want to swap out
content.php with content2.php using ajax.
Bad idea for at least two reasons:
1) It requires JavaScript, which is not always available.
2) The browser's address bar won't reflect the change, hence it would be
impossible to bookmark these pages.
Easy enough to do. *But* I
also want the URL to display mysite.com/content2.php so that users can
send that link to their friends. So in a sense, content2.php needs to
contain both just the bare content, and the full site (header+footer
+content).
Drop the entire AJAX idea, you don't really need it. In fact AJAX may
cause severe usability and accessibility problems if not used properly.
Instead build simple, flat pages, which include the header and footer.
It's easy, reliable and efficient.
There really needs to be a better way to do this. Most sites use the
same and header and footer across all pages, there's really no need to
reload them every time a user clicks a link.
You're trying to over-optimize and will cause new problems with that
approach. There's nothing wrong with reloading header and footer on
every page. Images (if there are any) are cached and some KB of HTML
don't really matter. One URL, one document. It's that easy.
<snip>
>> Anyway, I guess you're right about the over-optimizing. I've scratched
the Ajax stuff altogether. I'll look at it again in the future if it
becomes a problem. Gmail and other sites (like DeviantART) do
something like what I was mentioning, so there must be a benefit to
it, and it's definitely do-able.
Their reasoning isn't necessarily optimization, it's to enhance the
web UI for the users, and make interacting more intuitive. However, in
Gmail, the user always has the option of using the standard HTML
interface.

If you're turning to "Ajax" to optimize things, you're either
optimizing prematurely, or not looking at the right places for dealing
with bottlenecks.

--
Curtis

Actually, there was one other reason I wanted to use Ajax. I wanted
the menu and the main content to load separately from eachother. I'm
going to have a tree menu, that expands as you click on it. I don't
want to refresh the page the entire page every time a user clicks
something. Yes, I could use *just* javascript for that, but I suspect
there will be hundreds, or even thousands of entries one day, so I
don't necessarily want to load the whole thing at once. And when a
user clicks a category, the main page should show a more detailed
listing...but the idea is that the user doesn't have to wait for it to
load if he doesn't want to. Anyway, not a big deal just yet.

Mark
As Curtis said - you're optimizing prematurely.

Only a very few sites in the world ever get "thousands" of entries.
Many don't even get "hundreds" of entries.

And even if you do - how long is an entry? 1K entries at 10 bytes
apiece is still only 10K - you probably have larger pictures than that.

If load time because a problem, then it's time to look at the problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 7 '08 #26

This discussion thread is closed

Replies have been disabled for this discussion.