| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#10 (permalink) |
|
SurPerson
On a golden path...
Joined in Jul 2004
Lives in front of my laptop
Hosted on Sync
437 posts
Gave thanks: 0
Thanked 1 Time in 1 Post
|
For subfolders, you could use
Code:
<?php
$x = $_GET['x'];
$f = $_GET['folder'];
$i = 2
while($_GET['folder'.$i]) {$f = $f."/".$_GET['folder'.$1]}
$ext = ".php";
$dir = "includes/";
if($f != "" && eregi("^[_a-z0-9-]", $f)) {
$f = $dir . $f . "/";
} else {
$f = $dir;
}
if(eregi("^[_a-z0-9-]", $x)) {
if(file_exists($f . $x . $ext)) {
include($f . $x . $ext);
} else {
include($dir . "notfound" . $ext);
}
} elseif(!$x) {
include($dir . "main" . $ext);
} else {
include($dir . "error" . $ext);
}
?>
__________________
Me: TeeJay Server: Sync (Statistics) Site: technoized.com (Statistics) chown -R us ./base |
|
|
|
|
|
#12 (permalink) |
|
Peaches!
Excelling Contributor
Joined in Jul 2003
Lives in Ottawa, Ontario, Canada
Hosted on Jose, Pass19
564 posts
Gave thanks: 0
Thanked 0 times
|
Code:
while($_GET['folder'.$i]) {$f = $f."/".$_GET['folder'.$1]}
PHP Code:
|
|
|
|
|
|
#13 (permalink) |
|
Registered User
Seasoned Poster
Joined in Jul 2004
31 posts
Gave thanks: 0
Thanked 0 times
|
In case you consider the url myscript.php?folder1=boo&folder2=yah&x=mypage to be unwieldy ...
You can also modify the regular expression to accept forward slashes in the folder except for at the beginning (to ensure the script only runs includes in directories under $dir). This allows you to use a url of the form myscript.php?folder=boo/yah&x=mypage. See code below: PHP Code:
|
|
|
|
|
|
#14 (permalink) |
|
L'Awesome Advocate
Super #1
Joined in May 2004
Lives in .au
Hosted on Mango
2,423 posts
Gave thanks: 1
Thanked 5 times
|
Actually Wolfy, fyi. My previous script does allow forward slashes in the address.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#15 (permalink) |
|
Third Plateau
Comfy Contributor
Joined in Apr 2004
Lives in East Hanover, New Jersey
Hosted on Nifty
272 posts
Gave thanks: 0
Thanked 0 times
|
Actually, you don't even need all of that checking with regexps. You just need to get rid of ".." from the string, since that's the only security issue.
If you're already stuck in includes/, and ".." is erased, hackers can't get out of it no matter how many slashes are used.
__________________
site (syberdave.net) - server (nifty) |
|
|
|