Page 1 of 1

Having a little problem with creating the Template System

Posted: Mon Sep 03, 2012 6:58 am
by Lykos22
I was watching the "Template System" tutorial for making a template system in a basic small site of four pages and i would like some help please, cause i got a little bit confused :? .

In the four pages index.php, about.php, products.php and contact.php I have included the same navigation manu like this:
<div id="menu">
			<ul>
				<li><a href="index.php" class="current">Home</a></li>
				<li><a href="about.php">About</a></li>
				<li><a href="products.php">Products</a></li>
				<li><a href="contact.php">Contact</a></li>
			</ul>
		</div>
so all pages are under the root folder fakesite, i haven't any pages folder with pages inside to include in the index page by GET variables.
My question is how is going to be in this case the stucture and the check to make sure that if a user types in the url bar for e.g. localhost/fakesite/forum.php (which forum.php doesn't exist at all in my site) will redirect him to the index page, and show him only the four pages that are in the array with the existing pages?

Re: Having a little problem with creating the Template Syste

Posted: Tue Sep 04, 2012 12:42 pm
by jacek
If someone tries to go to /fakesite/anything.php they will just get the 404 not found page, so you could set up a custom 404 page to do the redirect. If you are using my system you could redirect them if $_GET['page'] is not set or the page was not found, I think I actually did something like that in the tutorial.
if (!isset($_GET['page') || in_array("{$_GET['page']}.page.inc.php", scandir('./pages'))){
    header('Location: ?page=index');
    die();
}
Something like that anwyay.

Re: Having a little problem with creating the Template Syste

Posted: Wed Sep 05, 2012 6:51 am
by Lykos22
Thanks for the reply Jacek!
Well ok, off course the 404 page :roll: !! but.. how exactly is going to be this redirect? :?
if ( ????? ){
        header('Location: 404.php');
        die();
}
I guess i'll need something like: in_array("anything.php", scandir('fakesite')), or something like this??
And where sould be placed this check? in init.php??

Re: Having a little problem with creating the Template Syste

Posted: Sun Sep 09, 2012 7:39 pm
by jacek
What would $_GET['page'] be if you were on the page that should not exist ? It could something simple like
if (strpos('/', $_GET['page']) !== false){
    // 404
}
which should work for any sub folder.