Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this practical to do with php? - dynamically loading menu

Status
Not open for further replies.

lennon123

Technical User
Apr 12, 2008
19
GB
hi guys,
I want to make a small 8 page site. Every page needs to have the same menu appearing on the side and top as they will be the navagation. Then the main content of the page needs to be dynamically loaded with php. Is there any way of having one page that is dynamically loaded in with the menu system on and then the other with dynamically loading text files? I guess my question is- is this practical to do with php or is it best sticking to just css and tables? Any response is appriciated
thanks
 
Didn't we just answer this in your other post?

Neither CSS nor tables will actually load external text files onto a web page So I'm not sure why you would want to do it that way. Additionally using tables for layout is a discouraged practice these days.

Anyway, you can use includes to load the textfiles. its very simple thing to do.

And use the url to pass and ID of the textfile to be loaded.

For example:

Code:
<a href="mainnavigationpage.php[red]?page=welcome[/red]">Welcome Page</a>
<a href="mainnavigationpage.php[red]?page=services[/red]">Services</a>
<a href="mainnavigationpage.php[red]?page=contact[/red]">Contact Information</a>


[green]\\Then in your PHP section look for a value in the URL query string:[/green]

if(isset($_GET['page'])){
[green]\\include file depending on value of page variable.[/value]
$section=$_GET['page'];
include($page . ".txt");
}

This would include a textfile named like the value in $page.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Sorry if this sounds mean but you plainly don't understand what PHP is nor what CSS and HTML is.

I'd suggest you swot up on that first.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
ok have read up... realise my question didnt really make much sense. I now have my menu working using the above code (it is displaying the correct variable in the query string for each page). The trouble is I just dont know the syntax for the

"[green]\\include file depending on value of page variable.[/value]"

bit. Can anyone help
 
never mind... that qu doesnt make sense either! sorry
 
a brief fix to vacunita's code for you

Code:
<a href="mainnavigationpage.php?page=welcome">Welcome Page</a>
<a href="mainnavigationpage.php?page=services">Services</a>
<a href="mainnavigationpage.php?page=contact">Contact Information</a>


//Then in your PHP section look for a value in the URL query string:
//set up the directory variable to tell php where to look for your pages

$directory = ''; //include the trailing slash

//if the page variable is set (clicked by user) then use this.  otherwise use defaultpage
$page = isset($_GET['page']) ? trim ($_GET['page']) : 'defaultpage';

//list all the permitted pages to prevent users from fishing
$permittedPages = array ( 'pageone', 'pagetwo', ...); 

//if the page requested is not a permitted page, then reassign to defaultpage
$page = in_array($page, $permittedPages)? $page ; 'defaultpage';

//load the page to the browser
include_once $directory . $page . 'txt';

 
thank you v.much jpadie. Ok I can see what is going on but for some reason it isnt loading the correct page. I have all my pages in the same directory on the root of the website. Can you take a lot at this code and point out anything that might be stopping this from working? If you can it would be much appreciated
cheers


<?php include("menu.php");
echo '<p>Hello World</p>';
//Then in your PHP section look for a value in the URL query string:
//set up the directory variable to tell php where to look for your pages
$directory = ' //include the trailing slash

//if the page variable is set (clicked by user) then use this. otherwise use defaultpage
$page = isset($_GET['page']) ? trim ($_GET['page']) : '
//list all the permitted pages to prevent users from fishing
$permittedPages = array ( '../about.php', '../admin.php', '../contact.php', '../education.php', '../home.php' '../issues.php', '../method.php', '../onsite.php', '../plans.php', '../soil.php', '../survey.php',);

//if the page requested is not a permitted page, then reassign to defaultpage
$page = in_array($page, $permittedPages)? $page ; '
//load the page to the browser
include_once $directory . $page . 'txt';

?>
 
as a guess, try taking out the ../ from elements of the permitted pages array

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Mi example was quite crude. japdie's fix is indeed the more comprehensive method, as it checks for pages that should and should not be requested.

Preventing any possible fishing or other problems derived from requesting a nonexistent page.

As an added bonus this method allow for people to actually bookmark the page they need instead of just the index page.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top