Having a little problem with creating the Template System

Ask about a PHP problem here.
Post Reply
Lykos22
Posts: 19
Joined: Sat Mar 24, 2012 9:03 am

Having a little problem with creating the Template System

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Having a little problem with creating the Template Syste

Post 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.
Image
Lykos22
Posts: 19
Joined: Sat Mar 24, 2012 9:03 am

Re: Having a little problem with creating the Template Syste

Post 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??
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Having a little problem with creating the Template Syste

Post 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.
Image
Post Reply