icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Dynamic Includes pt 2

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old August 12th, 2004, 4:36 AM   #1 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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);
}

?>
to achieve
Code:
http://www.domain.ext/?x=page
How could I edit this to allow me to use a another string. For example I want to add a $folder variable to get
Code:
http://www.domain.ext/?folder=foldername&x=page
Where page is inside foldername
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 4:44 AM   #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/";
}
That should work.
__________________
alex.honeywell [ seigousei.net - pass19, binuweb.com - jose ]
AlexH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 5:09 AM   #3 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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/";
}
and it's still not working. Help?
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 5:31 AM   #4 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 8:59 AM   #5 (permalink)
Registered User
Seasoned Poster
 
Joined in Jul 2004
31 posts
Gave thanks: 0
Thanked 0 times
Smile Voila

PHP Code:
<?php

$x 
$_GET['x'];
$dir "includes/";
$f $_GET['folder'];

if ( 
$f != "" && eregi("^[_a-z0-9-]$"$f) ) {
    
$f $dir $f "/";
} else {
    
$f $dir;
}

$ext ".php";

if(
eregi("^[_a-z0-9-]"$x)) {
    if(
file_exists($dir $x $ext)) {
        include(
$f $x $ext);
    } else {
        include(
$dir"notfound" $ext);
    }
} elseif(!
$x) {
    include(
$dir "main" $ext);
} else {
    include(
$dir "error" $ext);
}

?>
Does exactly the same as the last script without changing the $dir variable.

-wolf
Wolfy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 9:57 AM   #6 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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:
<?php

$x 
$_GET['x'];
$f $_GET['folder'];
$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);
}

?>
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 12:24 PM   #7 (permalink)
Registered User
Seasoned Poster
 
Joined in Jul 2004
31 posts
Gave thanks: 0
Thanked 0 times
It comes to something when I make typos with copy and paste!

Ick. I need some sleep soon.

I'm glad you got it working though.

-wolf
Wolfy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 1:38 PM   #8 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 12th, 2004, 1:55 PM   #9 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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
The previous code works well, now I just need to know how to manually extend it myself.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On