Ryan's District Boards

Computer, programming, and webmaster help , support , tips and tricks => Tutorials Zone! => Internet webmaster computer programming technology tips and tricks => PHP tutorials => Topic started by: onlygodcanjudgemee on May 22, 2006, 08:39:31 AM

Title: PHP include();, A very nifty trick
Post by: onlygodcanjudgemee on May 22, 2006, 08:39:31 AM
Even if you don't know any php this trick is easy to use and will save you a lot of time when updating the layout of you site.

1. First make the layout of your site, leaving the table or field where you want the main content to appear blank. Save it as a .php.

2. Then put the content in individual files as plain text/ content.

3. Insert this code in the content area of your layout file:

<?php
$page 
$_REQUEST['page'];
if(!
$page){$page main.html}
include(
$page);
?>



4. The last step in using this trick is to alter your hyperlinks. Instead of linking to main.html and guestbook.html and so on, you know link to ?page=main.html

That's it!
Here's an example to help you understand better:

index.php

<html>
<head>
<title>This is a test</title>
</head>
<body>
<a href=?page=main.html>Mainpage</a> - <a href=?page=second.html>Second page</a><br><br>
<?php
$page 
$_REQUEST['page'];
if(!
$page){$page main.html}
include(
$page);
?>

</body>
</html>



main.html

This is the mainpage...<br>
It is nice



second.html

This is another page...<br>
It is also nice