I constantly use the PHP INCLUDES feature on my site, & recently ran into a problem that I'm not sure is solveable at the moment & I'm hoping someone will have a solution.

I'm aware that PHP INCLUDES is ususally for content that you want to keep constant over many pages, but I use it for modifying the main content of my site.

My home page is basically static (and constant throughout the entire site) except for the main content on the page, the main content is served by the PHP INCLUDES function. In addition, when a link is pressed, the main content changes to reflect the information pertaining to the link that was pressed.

The links on my site resemble this format: index.php?page=tournaments.php or http://www.mysite.com/index.php?page=tournaments.php

The main content area on my page uses the INCLUDES function with the following codes, it allows the main content "news.php" to be swapped with another page selected on the menu links.
<? if ( $page=='' ) { $page="news.php"; $l="?"; } else { $page="$page"; }?>
<?php include("$page"); ?>

Many people using INCLUDES use them to modify Headers/Footers while the rest of the page may have areas using INCLUDES depending on the page being viewed. My dilemma lies in the way the page is served information from a new page that is being loaded.

I would like to have a dynamic banner that is below the header, that also uses INCLUDES along with the main content of the site. Basically, I would like the Banner change depending on the link selected to match the content on that particular page. It didn't sound like a difficult problem at first because most people keep the entire content to be modified as a single file, but I would like to change multiple INCLUDES at the same time between different pages after selecting a link. The solution to my problem should serve content about the loading page (i.e. the banner & main content) from 2 sources, but being displayed at the same time based on the page selected from the menu.

Does anyone have any idea how I could make that work? Any help would be appreciated. Thank you.

It would be easier for you to use switch.
e.g.

switch($page) {
default:
$content = "news.php";
$title = "News page/Home page";
break;

case "links":
$content = "links.php";
$title = "Links page";
break;

case "tournaments":
$content = "tournaments.php";
$title = "Tournaments page";
break;
}

etc etc.
those are just some examples where you can also add

<?=$title?>

within your html <title> tags.
Now you can include the same as before in the page

<?php include("$content"); ?>

Why bother enquoting $context in the include statement? Just slows down the parser...

handy for pages generated by those dreadfull wysiwyg things naming a file bob's-page.html

But why would that in anyway affect the variable? I mean, all you are doing by using "$context" is saying to PHP:

I'm typing some text here, feed this into the parser. If you find any variables, then evaluate them.

So essentially it's evaluating $context, and then sending the results off to the include() function, as apposed to just sending it off; if you see what I mean...

Well its a language construct rather than a function, And its more flexable using both ( and " ..
speed difference will be un-noticed on a small/non-busy site, unless he ends up getting 100k hits a month or more.
using them both will enable use of ssi and so on. where some servers dont like seeking ( using 'something' or just (something) ) and will get errors like "Stream does not support seeking" or similar.
Just tryin to be flexable is all :x

Ah, I wasn't aware of this...

Me either till a few weeks ago ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.