| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (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
|
Dynamic Includes pt 2
I'm currently using
Code:
<?php
$x = $_GET['x'];
$dir = "includes/";
$ext = ".php";
if(eregi("^[_a-z0-9-]", $x)) {
if(file_exists($dir . $x . $ext)) {
include($dir . $x . $ext);
} else {
include($dir . "notfound" . $ext);
}
} elseif(!$x) {
include($dir . "main" . $ext);
} else {
include($dir . "error" . $ext);
}
?>
Code:
http://www.domain.ext/?x=page Code:
http://www.domain.ext/?folder=foldername&x=page
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#2 (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
|
Change $dir = "includes/"; to
Code:
$f = $_GET['folder'];
if ( $f != "" && eregi("^[_a-z0-9-]$", $f) ) {
$dir = $f;
} else {
$dir = "includes/";
}
|
|
|
|
|
|
#3 (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
|
It can't seem to locate the file.
I've tried editing it to Code:
if ( $f != "" && eregi("^[_a-z0-9-]$", $f) ) {
$dir = "includes/" . $f . "/";
} else {
$dir = "includes/";
}
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#4 (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
|
Got it to work, was a problem with the eregi bit. But is there a way around this into not changing $dir?
I'm saying this because some of my files are using $dir and when you change it, it screws up.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#5 (permalink) |
|
Registered User
Seasoned Poster
Joined in Jul 2004
31 posts
Gave thanks: 0
Thanked 0 times
|
PHP Code:
-wolf |
|
|
|
|
|
#6 (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
|
Omgsh thanks for that Wolfy, you did a few typos in your new code but I got it working.
Thanks for all the replies and help as well Alex Working code PHP Code:
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#8 (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
|
You think you need sleep? It's almost 3am over here and I'm meant to "wake up" in 3 hours to got to school.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|
|
|
#9 (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
|
Ah hey guys, another question. I think that I will be having lots of subfolders, is there a chance where someone could teach me how to use the variables to allow a subfolder in?
Code:
http://www.domain.ext/?folder=name&folder2=name&folder3=name&page=name
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|