This question already has an answer here:
so my index page looks like this
<?php include 'header.php';?>
<main id="main" role="main">
<?php
if ($_GET['page'] == "") {
if ($_POST['page'] <> "") {
$page = $_POST['page'];
}
else {
$page = "homepage";
}
}
else {
$page = $_GET['page'];
}
switch($page) {
case "about": include "about.php"; break;
case "mission": include "mission.php"; break;
?>
</main>
<?php include 'footer.php';?>
The header got a standard title tag, my question is how can i change the title for each index.php?page=page-name
</div>
By the time your page check has started, header.php
has already been interpreted. So there is no way to inject the title unless you put the page check above the title.
Additionally, since you're checking both GET
and POST
, you might consider simplifying your code as follows:
<?php
switch($_REQUEST['page']) {
case "about":
include "about.php";
break;
case "mission":
include "mission.php";
break;
default:
include "homepage.php";
}