Page 1 of 1

Extensible Applications thru Modules

Posted: Wed May 24, 2006 1:14 pm
by MrPotatoes
i have started to work with an MVC frameworkt hat made things alot easier for me especially in terms of clean easy to read code. with this base code i was going to start writing a very large application mostly for my own needs and for fun. but i was going to keep everything well documented and well written. i don't want to write something and then have to come back and changeit all

the application that i'm building is to have modules which make the system extensible. like modules in PHP-Nuke or PostNuke or Dragonfly. these modules could be anything from forums to blog.

now what i need to do is have it so that the front controller (index.php) can direct you to the correct module whichever it is that you want. the main thing that i wanted to do is so that the user cannot go directly to the folder.

so for instance if they go to my site and type
http://www.my_site.com/index.php/modules/blog/index.php that is invalid
http://www.my_site.com/modules/blog/index.php this should be as well as ti's going directly to the folder's index which i do not want to allow

if they click on a blog link on the main page the link hould look like this:

http://www.my_site.com/blog/ || http://www.my_site.com/blog/index.php

this isn't directly going to either the folder and i wanted this to be valid.

my problem is getting it to work like that and i don't know exactly how to do this. i've tried screwing with the URL in the root index.php but that doesn't help because if you goto the folder directly you can still access it. i guess and error page would help that part but the fact taht it still goes there and no other way is really bothering me

some theory and psuedo code would help alot. i hope i explained it in enough detail.

thank you in advance

Posted: Wed May 24, 2006 1:58 pm
by bdlang
Two relatively simple methods, either use mod_rewrite if on Apache, or have some logic in a default index.php script within each directory that redirects them to the main index page via header(). The advantage of using mod_rewrite is that any request to these 'off-limits' directories can be made to redirect to the main index.php script, whereas the method using a PHP call to header() relies on the user actually visiting the '/blog/' path or '/blog/index.php' to work. If they request some other file, e.g. '/blog/file_you_cant_access.html', it will still serve it up.

Alternatively, you could use rules to block access using the Apache 'Directory' and 'Deny/Allow' controls, but they'll just wind up giving your users 403 Forbidden errors, not redirecting to the main site index.

Posted: Wed May 24, 2006 2:16 pm
by MrPotatoes
bdlang wrote:Two relatively simple methods, either use mod_rewrite if on Apache, or have some logic in a default index.php script within each directory that redirects them to the main index page via header(). The advantage of using mod_rewrite is that any request to these 'off-limits' directories can be made to redirect to the main index.php script, whereas the method using a PHP call to header() relies on the user actually visiting the '/blog/' path or '/blog/index.php' to work. If they request some other file, e.g. '/blog/file_you_cant_access.html', it will still serve it up.

Alternatively, you could use rules to block access using the Apache 'Directory' and 'Deny/Allow' controls, but they'll just wind up giving your users 403 Forbidden errors, not redirecting to the main site index.
thank you on the reply. i was actually thinking about mod_rewrite but there are a few reasons i wanted to shy away from that

1. if i use mod_rewrite then people that don't have it activated are screwed. since i plan for others to be using my system that's a no-no
2. i've never worked with it ::ashamed::

the second idea i'm more of a fan of because it makes more sence. what i was thinking of doing tho is having an index.html that does not allow directory access and atop of all the scripts i'd have a define to check for (it would only be defined cia the root index and you still wouldn't be able to access it directly) and a user auth check up top. it's worked before i just haven't done it yet. trying to get this to work

would there be a way to check the URL and then trace thru the folders in it's given segment and then see if it exists?

for isntance: http://www.mysite.com/modules/forums

the root (i dunno how this will work tho :() would read in the url given, goto the modules folder and search for the forums folder. if it's there it redirects you to the forums index.php

this is an example of dragonfly on my localhost server

http://localhost/df/modules/Forums/index.php or
http://localhost/dfmodules/Forums/
access is denied for each of these

but if you goto http://localhost/df/index.php?name=Forums
you can get into the forums.

[edit]
hmmmmm. now i'm starting to retrace my steps...

i think i might do this via mod_rewrite as an option within the system

the ideas were to not allow direct access for one and second i wanted to make sure that the URLs didn't show the system's folder hierarchy. that would be bad. but if i do that ?name="whatever module name here" then i can have it get the information from the module's index. but to get it's functionality without actuall having to be in there.

i guess that's one more piece of functionality that i've got to add no? we'll see

if you have anymore ideas on how to make this simple and nice please, tell me :D :D :D
[/edit]
THANK YOU