468,133 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

opening different includes within the same div

Hi, I am very new to PHP so please go easy on me.

I have a page with 2 divs next to each other, a menu in the left and
content in the right. Now what I want to know, is it possible to
chenge the file being included in the content div when I click on
different links in the menu div?

So basically, when I click on the 'News' link it includes the file
'news.php' in the content div and so on for the rest of the menu
items.

Here is a list of links within my menu and the corresponding files
that need to be opened in the content div when each is clicked on:

Home main.php
Team team.php
Links links.php
Contact contact.php

I would be greatful for any help!

Mar 4 '08 #1
28 1655
On 4 Mar, 10:21, timhaynes1...@googlemail.com wrote:
Hi, I am very new to PHP so please go easy on me.

I have a page with 2 divs next to each other, a menu in the left and
content in the right. Now what I want to know, is it possible to
chenge the file being included in the content div when I click on
different links in the menu div?

So basically, when I click on the 'News' link it includes the file
'news.php' in the content div and so on for the rest of the menu
items.

Here is a list of links within my menu and the corresponding files
that need to be opened in the content div when each is clicked on:

Home main.php
Team team.php
Links links.php
Contact contact.php

I would be greatful for any help!
You are describing a CMS (Content Management System).

Install Mambo or Joomla or some other CMS and it is all done for you.
Mar 4 '08 #2
You are describing a CMS (Content Management System).
>
Install Mambo or Joomla or some other CMS and it is all done for you.
Well no, because that is a little complex for what I want. I only
need to open each of the 4 includes in a specific <divwhen the
relevant link is clicked on.

Thanks anyway.

Mar 4 '08 #3
You can use Frames for this. If you want to influence the content of a
DIV that is already there without loading the whole page, you are
looking at AJAX, but I think I already suggested that.

A CMS may seem long winded, but as you decide to develop your site
further, you will end up building more and more of what folks have
already built before.
Yes a CMS is probably sensible and in the long run I may eventually
use one but for now I just want to learn PHP and i've been told the
best way to learn is to actually build a site using some PHP. I never
use frames, satan invented these! AJAX, sounds interesting, I think I
might follow this up, thanks for the advice.
Mar 4 '08 #4
On 4 Mar, 11:17, timhaynes1...@googlemail.com wrote:
You can use Frames for this. If you want to influence the content of a
DIV that is already there without loading the whole page, you are
looking at AJAX, but I think I already suggested that.
A CMS may seem long winded, but as you decide to develop your site
further, you will end up building more and more of what folks have
already built before.

Yes a CMS is probably sensible and in the long run I may eventually
use one but for now I just want to learn PHP and i've been told the
best way to learn is to actually build a site using some PHP. I never
use frames, satan invented these! AJAX, sounds interesting, I think I
might follow this up, thanks for the advice.
If you're going the AJAX route (a sensible move IMO - that is why it
was the first of the sggested options), install XAJAX and work with
that.
Mar 4 '08 #5
If you're going the AJAX route (a sensible move IMO - that is why it
was the first of the sggested options), install XAJAX and work with
that.
Okay, just out of interest, if I went down the route of iframes, how
would i include, let's say, 'team.html' within the iframe when i click
on the 'team' link?
Mar 4 '08 #6
On 4 Mar, 11:59, timhaynes1...@googlemail.com wrote:
If you're going the AJAX route (a sensible move IMO - that is why it
was the first of the sggested options), install XAJAX and work with
that.

Okay, just out of interest, if I went down the route of iframes, how
would i include, let's say, 'team.html' within the iframe when i click
on the 'team' link?
You use the target parameter on the anchor to direct which frame to
operate against.
Mar 4 '08 #7
On 4 Mar, 11:59, timhaynes1...@googlemail.com wrote:
If you're going the AJAX route (a sensible move IMO - that is why it
was the first of the sggested options), install XAJAX and work with
that.

Okay, just out of interest, if I went down the route of iframes, how
would i include, let's say, 'team.html' within the iframe when i click
on the 'team' link?
You use the target parameter on the anchor to direct which frame to
operate against.
Mar 4 '08 #8
On 4 Mar, 12:54, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 4 Mar, 11:59, timhaynes1...@googlemail.com wrote:
If you're going the AJAX route (a sensible move IMO - that is why it
was the first of the sggested options), install XAJAX and work with
that.
Okay, just out of interest, if I went down the route of iframes, how
would i include, let's say, 'team.html' within the iframe when i click
on the 'team' link?

You use the target parameter on the anchor to direct which frame to
operate against.
Okay, i think I understand. What would the code of the link and
iframe look like?
Mar 4 '08 #9
You use the target parameter on the anchor to direct which frame to
operate against.
Okay, I think I understand. What would the code of the link and
iframe look like?
Mar 4 '08 #10
On 4 Mar, 13:00, timhaynes1...@googlemail.com wrote:
You use the target parameter on the anchor to direct which frame to
operate against.

Okay, I think I understand. What would the code of the link and
iframe look like?
http://www.google.co.uk/search?q=target+frame+html
Mar 4 '08 #11
timhaynes1985 wrote:
Here is a link to the site in question
http://blindsya.awardspace.com/index.php ... let's just pretend we're
dealing with one include file. So, when I click on the 'Team' link in
the menu to the left I want 'team.html' to be included in the 'CONTENT
DIV' on the right.
Try thinking about it the other way around. Instead of "team.php" being
included into your template file, include the template file into
"team.php". That is, team.php contains:

<?php include('top.php'); ?>
<p>Blah blah blah... team info...</p>
<?php include('tail.php'); ?>

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 34 days, 19:20.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Mar 4 '08 #12
On 4 Mar, 13:04, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
timhaynes1985 wrote:
Here is a link to the site in question
http://blindsya.awardspace.com/index.php... let's just pretend we're
dealing with one include file. So, when I click on the 'Team' link in
the menu to the left I want 'team.html' to be included in the 'CONTENT
DIV' on the right.

Try thinking about it the other way around. Instead of "team.php" being
included into your template file, include the template file into
"team.php". That is, team.php contains:

<?php include('top.php'); ?>
<p>Blah blah blah... team info...</p>
<?php include('tail.php'); ?>

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 34 days, 19:20.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
That was sort of my option 2 suggestion.
Mar 4 '08 #13
This is so weird! A couple of years ago I built a site (not a very
good one) and on the left I had a menu and when I clicked on each link
it opened up the coresponding .php file in an include on the right.

Please don't blaze me down, i'm terrible at programming i know but it
went something like this ...

<a href="index.php?content=news.php>News</a>

That would then open the file in an include somewhere else that i had
named 'content'.

That above code is very rough and very incorrect but it was definitely
something like that.
Mar 4 '08 #14
Right okay ... thanks for the advice, I googled what you said and came
up with a few interesting bits of info.

Out of these bits I was able to create the following code ...

<a href="index.php?page=team">Team</a>

- For the link.

<DIV id="content">
<?php include("$page.html"); ?>
</DIV>

- For where I want the included file to be shown.

This works perfectly, however, when I visit my index.php it shows the
error message ...

Warning: main(.html): failed to open stream: No such file or directory
in /home/www/blindsya.awardspace.com/index.php on line 33

Warning: main(): Failed opening '.html' for inclusion
(include_path='.:/usr/local/php4/share/pear') in /home/www/
blindsya.awardspace.com/index.php on line 33

Am I right in saying I have to declare a default file to be included
for this messgae not to appear?
Mar 4 '08 #15
ti***********@googlemail.com a écrit :
Am I right in saying I have to declare a default file to be included
for this messgae not to appear?
Yes, and you should also consider protecting your include, for example
by doing include('./' . $page . '.html')

if you keep using yours, I could use the URL
"index.php?page=http://www.mysite.org/myphphack" and have *my php hack*
into the file myphphack.html, which *your code* would include and
execute with *your rights*, *your variables* and (if you have one) *your
database access*

I guess you understand the exploit. Data provided in URLs should *never*
be handled as is.

--
Guillaume
Mar 4 '08 #16
Yes, and you should also consider protecting your include, for example
by doing include('./' . $page . '.html')

if you keep using yours, I could use the URL
"index.php?page=http://www.mysite.org/myphphack" and have *my php hack*
into the file myphphack.html, which *your code* would include and
execute with *your rights*, *your variables* and (if you have one) *your
database access*

I guess you understand the exploit. Data provided in URLs should *never*
be handled as is.

--
Guillaume
Ahhh okay, thank you!

I have now ammended my code and it looks like this ...

<DIV id="content">
<?php include('./' . $page . '.html'); ?>
</DIV>

Is that more correct?

To declare a default include when index.php is opened will I have to
fiddle around with the php.ini file? Very very very limited info
about this online!
Mar 4 '08 #17
timhaynes1985 wrote:
I have now ammended my code and it looks like this ...

<DIV id="content">
<?php include('./' . $page . '.html'); ?>
</DIV>

Is that more correct?
You probably still want to check that $page has nothing nasty in it.

<DIV id="content">
<?php
# Find out what page they want;
$page = $_GET['page'];

# Check no slashes in $page;
if (preg_match('#/#', $page))
die('Go away!');

# Check file really exists;
if (!file_exists($page . '.html'))
die('Huh?');

# Everything OK, show file.
include('./' . $page . '.html');
?>
</DIV>
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 34 days, 22:33.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Mar 4 '08 #18

<ti***********@googlemail.comwrote in message
news:f2**********************************@u72g2000 hsf.googlegroups.com...
Hi, I am very new to PHP so please go easy on me.

I have a page with 2 divs next to each other, a menu in the left and
content in the right. Now what I want to know, is it possible to
chenge the file being included in the content div when I click on
different links in the menu div?

So basically, when I click on the 'News' link it includes the file
'news.php' in the content div and so on for the rest of the menu
items.

Here is a list of links within my menu and the corresponding files
that need to be opened in the content div when each is clicked on:

Home main.php
Team team.php
Links links.php
Contact contact.php

I would be greatful for any help!
If you want to do it with php, you're going to have to reload the page. You
could have a different page and use links, or use a form.

The preferred method would be javascript (perhaps with a php backup if js is
disabled). You could possibly even do something with CSS if you were
flexible about the layout.

Mar 4 '08 #19
On 4 Mar, 16:19, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
timhaynes1985 wrote:
I have now ammended my code and it looks like this ...
* * * <DIV id="content">
* * * * <?php include('./' . $page . '.html'); ?>
* * * </DIV>
Is that more correct?

You probably still want to check that $page has nothing nasty in it.

<DIV id="content">
<?php
* * * * # Find out what page they want;
* * * * $page = $_GET['page'];

* * * * # Check no slashes in $page;
* * * * if (preg_match('#/#', $page))
* * * * * * * * die('Go away!');

* * * * # Check file really exists;
* * * * if (!file_exists($page . '.html'))
* * * * * * * * die('Huh?');

* * * * # Everything OK, show file.
* * * * include('./' . $page . '.html');
?>
</DIV>

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 34 days, 22:33.]

* * * * * * * * * * * * * * * *Bottled Water
* * * * *http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Weeerrwwww there, I used this code exactly and it got rid of my menu
to the left which i use an include for! Not quite sure what went
wrong there. Anyway, does anyone pleeeease have any suggestions about
setting the default file to include? I'm going out of my mind and
would appreciate any help.
Mar 4 '08 #20
ti***********@googlemail.com wrote:
>I have to say that in the time we have been having this conversation
you could have installed one of the simple CMS systems and been
customising it already.- Hide quoted text -

- Show quoted text -

Yes, I do think for myself but it's very hard when you keep using
pronouns to explain things! I don't know what 'it' is!
Well learn to read then. There is only one subject in the sentence and as is
normal in an English sentence, the pronoun refers to the subject. Sheesh!
Mar 4 '08 #21
On 4 Mar, 22:04, "Paul Lautman" <paul.laut...@btinternet.comwrote:
timhaynes1...@googlemail.com wrote:
I have to say that in the time we have been having this conversation
you could have installed one of the simple CMS systems and been
customising it already.- Hide quoted text -
- Show quoted text -
Yes, I do think for myself but it's very hard when you keep using
pronouns to explain things! *I don't know what 'it' is!

Well learn to read then. There is only one subject in the sentence and as is
normal in an English sentence, the pronoun refers to the subject. Sheesh!
And, as is also normal in English, when a question is asked and much
debated then several nouns arise. So I can understand why an idiot
would refer to the subject! Perhaps it's a good thing I have a degree
in English Language. Wouldn't hurt if a few others on here would know
how to speak a language properly too.
Mar 5 '08 #22
ti***********@googlemail.com a écrit :
I have now ammended my code and it looks like this ...

<DIV id="content">
<?php include('./' . $page . '.html'); ?>
</DIV>

Is that more correct?
Yep, still I would recommand a process on your variable beforehand. You
can manage some unwanted strings ("../" could bring an include to any
file of your system if the server is misconfigured, which happens
sometimes), disallow some characters.

Or you could just be as secure as possible and only allow your defined
pages, if you have a list.
$available_pages = array('home', 'contact, 'team');
$page = in_array($_GET['page'], $available_pages) ? $_GET['page'] : '404';
include("./{$page}.html");

If you have some kind of sitemap, or a well defined site structure, you
should have (or be able to easily reconstruct) your pages array, so you
may apply this one. Thus, beside the 404 pages handle (in my example,
always a nice addition), you're sure that you won't include anything
that you did not specify.

That is always the best regarding security, do not take the user
submitted variables as is, pre-process them so you don't know what is
submitted but you know what you're not going to use.

Regards,

--
Guillaume
Mar 5 '08 #23
On 5 Mar, 09:31, Guillaume <ggra...@gmail.comwrote:
timhaynes1...@googlemail.com a écrit :
I have now ammended my code and it looks like this ...
* * * <DIV id="content">
* * * * <?php include('./' . $page . '.html'); ?>
* * * </DIV>
Is that more correct?

Yep, still I would recommand a process on your variable beforehand. You
can manage some unwanted strings ("../" could bring an include to any
file of your system if the server is misconfigured, which happens
sometimes), disallow some characters.

Or you could just be as secure as possible and only allow your defined
pages, if you have a list.
$available_pages = array('home', 'contact, 'team');
$page = in_array($_GET['page'], $available_pages) ? $_GET['page'] : '404';
include("./{$page}.html");

If you have some kind of sitemap, or a well defined site structure, you
should have (or be able to easily reconstruct) your pages array, so you
may apply this one. Thus, beside the 404 pages handle (in my example,
always a nice addition), you're sure that you won't include anything
that you did not specify.

That is always the best regarding security, do not take the user
submitted variables as is, pre-process them so you don't know what is
submitted but you know what you're not going to use.

Regards,

--
Guillaume
Wow, just implemented this and it's perfect! All my woes have gone.
Thank you for your help.
Mar 5 '08 #24
ti***********@googlemail.com a écrit :
Anyway, does anyone pleeeease have any suggestions about
setting the default file to include? I'm going out of my mind and
would appreciate any help.
Regarding my previous post with 404 handled (didn't noticed this reply
before, sorry >_<), you may also use the ? : method to apply a default
include.

$page = isset($_GET['page']) ? $_GET['page'] : 'default';
Then apply your checks on $page.

Regards,

--
Guillaume
Mar 5 '08 #25
On 5 Mar, 09:31, timhaynes1...@googlemail.com wrote:
On 4 Mar, 22:04, "Paul Lautman" <paul.laut...@btinternet.comwrote:
timhaynes1...@googlemail.com wrote:
>I have to say that in the time we have been having this conversation
>you could have installed one of the simple CMS systems and been
>customising it already.- Hide quoted text -
>- Show quoted text -
Yes, I do think for myself but it's very hard when you keep using
pronouns to explain things! I don't know what 'it' is!
Well learn to read then. There is only one subject in the sentence and as is
normal in an English sentence, the pronoun refers to the subject. Sheesh!

And, as is also normal in English, when a question is asked and much
debated then several nouns arise. So I can understand why an idiot
would refer to the subject! Perhaps it's a good thing I have a degree
in English Language. Wouldn't hurt if a few others on here would know
how to speak a language properly too.
Ahh personal abuse directed at someone who has spent a lot of time
tyrying to help you. What a pleasant person you are not.

Pray explain why I am an idiot for referring to the subject of a
sentence with respect to the use of pronouns? The sentence contained a
quite specifc subject, that being "simple CMS systems ". I can see
nothing else in that sentence that the "it" could possibly have
referred to.
Mar 5 '08 #26
On 5 Mar, 09:31, timhaynes1...@googlemail.com wrote:
On 4 Mar, 22:04, "Paul Lautman" <paul.laut...@btinternet.comwrote:
timhaynes1...@googlemail.com wrote:
>I have to say that in the time we have been having this conversation
>you could have installed one of the simple CMS systems and been
>customising it already.- Hide quoted text -
>- Show quoted text -
Yes, I do think for myself but it's very hard when you keep using
pronouns to explain things! I don't know what 'it' is!
Well learn to read then. There is only one subject in the sentence and as is
normal in an English sentence, the pronoun refers to the subject. Sheesh!

And, as is also normal in English, when a question is asked and much
debated then several nouns arise. So I can understand why an idiot
would refer to the subject! Perhaps it's a good thing I have a degree
in English Language. Wouldn't hurt if a few others on here would know
how to speak a language properly too.
I'm actually quite intrigued now, despite the fact that you have
directly insulted me.

Just how would you (with your English Language degree) have worded the
sentence:

"I have to say that in the time we have been having this conversation
you could have installed one of the simple CMS systems and been
customising it already."

avoiding the use of the pronoun?
Mar 5 '08 #27
On 5 Mar, 10:55, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
Grammatically, "it" could also refer to "the time" or "this conversation",
though neither of those would make sense in the context of customisation,
so it is logical to discard those as possible candidates for the noun
referred to by "it".
This was the point of my comment abut learing how to read. When one
reads, one reads in context.
Mar 5 '08 #28
..oO(Captain Paralytic)
>Just how would you (with your English Language degree) have worded the
sentence:

"I have to say that in the time we have been having this conversation
you could have installed one of the simple CMS systems and been
customising it already."

avoiding the use of the pronoun?
I have to say that in the time we have been having this conversation you
could have installed one of the simple CMS systems and been already
customising that one of the simple CMS systems that in the time we have
been having this conversation you could have installed."

Or something like that. Of course it (uh!) is a lot clearer now.

SCNR
Micha
Mar 6 '08 #29

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Colin McKinnon | last post: by
2 posts views Thread by Jawahar Rajan | last post: by
1 post views Thread by Don Sealer | last post: by
21 posts views Thread by Dan Tallent | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.