Forum Moderators: coopster

Message Too Old, No Replies

Questions on php includes and linking to them

         

jonnygoth

7:20 pm on Aug 31, 2006 (gmt 0)

10+ Year Member



I have been developing my first php site.
I will try to describe as best as possible.

What I have is a page that lays out what includes are required:
Header
Contect
Footer

Now i want to be able to link to the page include construct and automatically include the correct content file based on the link that is clicked.

IE: if you click on the about me link the content incluce will change to the aboutme include from the default home include you start off with when reaching the site.

I was told this is possible without a data base, but i dont know how to do that or with a data base either.

I know how to make includes and have them be pulled in from a normal href link, but that doesnt make it dynamic like i want it.

Can anyone help me with this and/or point me in the right direction i need to go to learn how to do this?

For server information:
php 4&5
mysql with phpmyadmin
apache
linux red hat
and all the typical normals of a web server.

Any help and discussion greatly appreciated.

eelixduppy

7:29 pm on Aug 31, 2006 (gmt 0)



Hello!

Try something like this:

test.php


<?php
include("header.html");

$page = $_GET['page'].'.html';
if(file_exists($page)) { //assuming the files exist in the same directory
include($page);
}

include("footer.html");
?>

Now for the links, you would just make them something like this:


<a href='test.php?page=home'>Home</a>

This link includes home.html into the content area.

I hope this has helped.

Best of luck!

*Note: There can be security issues if you are not careful including pages in this way.*