Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache and PHP, problem with variables
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Atle
Apprentice
Apprentice


Joined: 16 Sep 2004
Posts: 179

PostPosted: Wed Jun 08, 2005 3:07 pm    Post subject: Apache and PHP, problem with variables Reply with quote

Okay, I'm not sure what to search for to find a solution to this, so I'll ask here. Hop it's the right forum.

I've set up apache and php4, and it mostly works. But I have a problem getting variables parsed from forms (actually set in the URL) to be read by the PHP script. The URL might look something like this http://192.168.1.27/index.php?page=main

Most php in the page will work, but part of the code is:
Code:

if ( file_exists($page)  ){
   include($page);
    }
    else {
        echo ("Page=<p>$page</p>");
    }
}

This will not include the page, but will write <p>Page=</p> into the html. The problem is not that the file does not exist (or have the correct rights), but that the $page variable is not set.

The code works fine on a couple of other servers.

I have no idea where this bug comes from and where to start looking in order to solve this. Anyone know?
Back to top
View user's profile Send private message
Celtis
l33t
l33t


Joined: 05 Jul 2003
Posts: 737

PostPosted: Wed Jun 08, 2005 4:12 pm    Post subject: Reply with quote

It's not a bug, it's a configuration option, register_globals which is off by default. Have a look at http://uk.php.net/register_globals for reasons why the PHP devs themselves suggest that it stays off

Try using $_GET["page"] instead of just $page (it's better form and makes it easier to follow!).
Back to top
View user's profile Send private message
DavidMCS
n00b
n00b


Joined: 08 Feb 2004
Posts: 39
Location: Halifax, NS Canada

PostPosted: Wed Jun 08, 2005 4:19 pm    Post subject: Reply with quote

More than likely register_globals = Off in your php.ini.

You should actually write your scripts so they do not require register_globals to be turned on. Form variables with global scope can easily lead to security vulnerability problems. Instead access your posted form variables using the new superglobal arrays of $_POST and $_GET depending on the method your form uses to submit the data.

Try the following...

Code:

if ( file_exists( $_GET['page'] )  ){
   include($page);
    }
    else {
        echo ("Page=<p>$_GET['page']</p>");
    }
}


or this...

Code:


$page = $_GET['page'];

if ( file_exists($page)  ){
   include($page);
    }
    else {
        echo ("Page=<p>$page</p>");
    }
}



--
David-
Back to top
View user's profile Send private message
hanj
Veteran
Veteran


Joined: 19 Aug 2003
Posts: 1500

PostPosted: Wed Jun 08, 2005 8:36 pm    Post subject: Reply with quote

I'd be concerned about your code.. looks like you would be open to directory/file traversal. Not knowing your server configurations.. you may be able to read other files...

http://192.168.1.27/index.php?page=../../../etc/passwd for example.

or potentially cause a DoS via loop:

http://192.168.1.27/index.php?page=index.php

You may want to implement openbase_dir, safe_mode and client input filtering. Make sure you follow the above advise and use the $_GET array instead of turning on register_globals.. that would be a bad thing to do.

HTH
hanji
Back to top
View user's profile Send private message
Atle
Apprentice
Apprentice


Joined: 16 Sep 2004
Posts: 179

PostPosted: Wed Jun 08, 2005 11:00 pm    Post subject: Reply with quote

Thank you guys, both for the help and the security tips.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum