In the URLs you name the parameter p
but in your files.class.php
you actually test for $_GET['page']
. So either change the URLs to use page
as parameter or change the code to:
// in files.class.php instead of if(!isset($_GET['page']))
if(!isset($_GET['p'])){
// your code here...
} else {
// ...
}
In your original code, as $_GET['page']
does never exist, it always shows the index page.
Another thing that looks strange to me is the following (but maybe it is just how you set it up):
if(file_exists($_GET['page'].'.txt')){
// and lets include that then:
ob_start();
include("contents/". $_GET['page'] . '.php');
$content = ob_get_contents();
ob_end_clean();
}
You first check whether the text file e.g. about.txt
exists but then include a PHP file contents/about.php
. Is this intended? Does the PHP always exist if the text file exists?
UPDATE:
Also make sure that you properly check the value that you get from $_GET['page']
or however you call it in the end.
E.g. this call http://designed.sytes.net/index.php?page=../index
seems to kill your server (sorry it was unintentionally :( )
UPDATE 2:
In order to provide "some" security you could check whether $_GET['page']
is one of predefined values instead of checking whether a file with this name exists. E.g:
$valid_pages = array('home', 'about', 'services', 'contact');
if(isset($_GET['page']) && in_array($_GET['page'], $valid_pages) {
// include page here
}
else {
// redirect to home page
}
That makes sure that $_GET['page']
is not of form of relative pathes like ../index
. If it is not one of those values in $valid_pages
you redirect to the home page.