website template / using $_POST and $_GET from included file
Posted: Mon Mar 19, 2007 12:19 am
I wanted to apply a certain structure/template to every page in my website. The way it is set up now is with an index.php file taking GET requests and returning the corresponding page:
index.php:
The problem with this setup is that I can't use $_GET or $_POST from the page included by index.php. For example, I sometimes need to retrieve a post request in register.php. I either need to retrieve $_GET or $_POST requests from an included file, or I need a way to apply the template individually to each file and then have each page requested directly.
I tried the following but it didn't work:
index.php:
register.php:
The returned page had the content from register.php appended to the content from index.php (instead of being embedded in the content from index.php, which is what I wanted).
I don't know how to get around this. If you can, please help.
index.php:
Code: Select all
...
$return_page = "";
switch( $_GET["page"] ) {
case "home":
$return_page = "home.php";
case "register":
$return_page = "register.php";
case "about":
$return_page = "meta/about.php";
default:
"http404.php"
}
include_once($return_page);
...I tried the following but it didn't work:
index.php:
Code: Select all
<html>
<body>
...
<?php
function applyTemplate($content) {
echo $content;
}
?>
...
</body>
</html>register.php:
Code: Select all
<?php include_once("index.php");?>
<?php
$content = '
...
';
applyTemplate($content);
?>I don't know how to get around this. If you can, please help.