Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help please with includes

Status
Not open for further replies.

BizzyLizzy

Technical User
Nov 3, 2003
77
0
0
AU
Hi there.

Hope someone can help a complete php newbie.

currently our website has the following code. Very simple and I believe pretty insecure. (our hosters have register globals on).

<?php
$view = $_GET['view'];
?>

then

<?php include ("$view.php"); ?>

then in the links section of the navigation bar.

index.php?view=home
index.php?view=aboutus

etc etc (there are about 10 pages in all

The problem with this is that the resultant URL is shown as


Now correct me if I am wrong but isnt this terribly insecure? (I didnt write this by the way I inherited it.).

I have been told that using $_POST would be a better way but I am not sure how I go about changing things. Ideally I would like to have the url just shown as
Am I making any sense here? Hopefully one of you clever people can give me some assistance.

Many thanks

Lizzy
 
As a rule of thumb, you should never blindly trust anything comming from the client. That includes $_GET, $_POST, $_REQUEST, and $_COOKIES.

If you're going to use an approach like this, you should validate the view parameter. One way to do it would be to use a list of valid pages. For example:
Code:
$view = $_GET['view'];
$good_pages = array('home', 'aboutus', 'whatever');
if (in_array($view, $good_pages)) {
    include("$view.php");
} else {
    die("Invalid page");
}
 
Brilliant OK, thats sounds as though its going to be a bit more secure.

Presumably I should validate all my variables throughout the site as well - due to the fact that the hosters have global variables switched on.

I have just been going through the rest of the site and notice that there are an awful lot of variables are not set by default.

Anyway I will set the allowable pages in the index page and see how I go from there.

Lizzy
 
if your host has register globals turned on, either turn it off locally or move hosts.i would not trust an ISP to manage my data if it blindly ignored the advice of the writers of one of the core web applications. worse still would be if the host had considered the risks, read the advice and then still turned register-globals on. that would just be ignorant but reckless.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top