Craig321 said:rob:
Is your coding safer than mine and does it avoid all this stuff?
Tetsujin said:if i may be so bold...
best way i've found for handling the old '?page=blah' issue, is to store pages in database. so ?page=3 will go off and pull the record id=3 from a 'pages' table in the database to get the filename (or maybe the content directly). naturally some integer checking+casting on the $page input too.
Tetsujin said:if i may be so bold...
best way i've found for handling the old '?page=blah' issue, is to store pages in database. so ?page=3 will go off and pull the record id=3 from a 'pages' table in the database to get the filename (or maybe the content directly). naturally some integer checking+casting on the $page input too.
I find it easier just to define an associative array of all the pages I want to be 'includable', so if I go to index.php?page=blah then it looks up the array element with the key 'blah' and includes the correct fileTetsujin said:if i may be so bold...
best way i've found for handling the old '?page=blah' issue, is to store pages in database. so ?page=3 will go off and pull the record id=3 from a 'pages' table in the database to get the filename (or maybe the content directly). naturally some integer checking+casting on the $page input too.
Inquisitor said:I find it easier just to define an associative array of all the pages I want to be 'includable', so if I go to index.php?page=blah then it looks up the array element with the key 'blah' and includes the correct file
Inquisitor said:Well it means that only the pages that you want to be opened can actually be opened, so that eliminates a lot of security risks from the equation
Inquisitor said:Well it means that only the pages that you want to be opened can actually be opened, so that eliminates a lot of security risks from the equation
Thanks to robmiller whenever someone types in the wrong index.php?page= thing then it just displays the index pageBen said:hmm, how are you stopping people from going to say -
yoursite.com/pages/gallery.php directly?
this may not be revealed initally by index.php, but if someone managed to make
index.php?page=gallery error, then it'd reveal /complete/path/to/pages/gallery.php in the error.
Yes I know that. I'm talking about accessing the included php file directly, like I showed in the 2nd half of this post. Which was my point against Inquisitor's point!Craig321 said:Thanks to robmiller whenever someone types in the wrong index.php?page= thing then it just displays the index page
Not if you stop it from displaying errors, which you should do anyway.Ben said:hmm, how are you stopping people from going to say -
yoursite.com/pages/gallery.php directly?
this may not be revealed initally by index.php, but if someone managed to make
index.php?page=gallery error, then it'd reveal /complete/path/to/pages/gallery.php in the error.
Inquisitor said:Not if you stop it from displaying errors, which you should do anyway.
Besides, that code won't generate errors anyway. If the key does not exist in the array, it just displays a message saying the page could not be found
Also, I have all of the actual 'pages' in a password protected directory, so you can't just view the files themselves.
<?php
require('inc/global.php');
// page stuff here
require('main.php');
?>
if(!preg_match('#^/index.php.*#', $_SERVER['REQUEST_URI'])) {
die('You cannot view this page directly.');
}