473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

php include design question

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
25 2229

"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
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
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
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
..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
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
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
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
..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
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
..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
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
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
..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
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
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
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
..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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
11
by: Marc Ferry | last post by:
I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had no response. As this problem might be present on other OSes than HP-UX 10.20, I crosspost it here, in the hope of getting an...
1
by: Des Perado | last post by:
We have an elderly DOS-based system running on a Novell Netware server here, and an extensive intranet. Quite recently the board decided that some crucial info from the DOS system was to be made...
5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
8
by: Alex | last post by:
Hi, I have noticed that in an aspx page <!--#include virtual="Home.htm"--> acts the same as <!--#include File="Home.htm"--> when I am NOT in the root diectory of the site (I am aware that...
5
by: suresh_punniyakkodi | last post by:
Hellow to all, In am working in Dreamweaver, In my project i want to include flash files to this project, i am included flash to dreamweaver, that flash file is working in only design...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
6
by: Goran | last post by:
Hi all, this is just a "design" question. I'm unsure where to put my "#includes". Should I put it directly into headerfiles? Or into sourcefiles with a forward type declaration in...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.