Before I start, I am completely new to PHP. This is probably a stupid error and I am probably doing this in the worst way possible.
I have this code:
<?php
if (!isset($_GET['p'])) {
$url .= '?p=home';
header('Location:' . $url);
exit;
}
elseif (!isset($_GET['sp'])) {
header("Location: ".$_SERVER['REQUEST_URI'].'&sp=index.php';);
die();
}
include('/Page/' . htmlspecialchars($_GET["p"]) . '/' . htmlspecialchars($_GET["sp"]));
?>
Basically the url format is www.example.com/?p=PAGE&sp=SUBPAGE.php
The internal format from this will be /Page/PAGE/SUBPAGE.php
Reasons:
Each 'Post' will have it's own folder for it's resources. (
?p=) Then they can put anything within their folder and link to it with theSUBPAGE (&sp=).This keeps everything organised and stops any internal linking to anywhere but the
/page/area.
What's wrong:
If there is no Page (p) set I need to add
?p=homeas the default and if their is no SubPage (sp) set I need to add&sp=index.phpby default.If there is no Page then the SubPage will be reset to default.
If you are on a page
www.example.com/?p=blogthen it will add the subpage without removing the page (?p=blogto?p=blog&sp=index.php)However if there is no page then the subpage will be reset to default.
The question:
How can I come about this?
Thank you, in advance.