Jump to content

dynamic routing


dmikester1

Recommended Posts

I think this is probably the right forum for this question.  I'm not using a specific framework but am working on writing my own dynamic router.  What is the general consensus about which $_SERVER variable to use to route the request.  After doing a ton of research, I've found people recommending PATH_INFO, ORIG_PATH_INFO, REQUEST_URI, PHP_SELF, SCRIPT_FILENAME, or SCRIPT_NAME.  In February 2012, is there a general consensus among PHP coders about which is the best one to use?  Or do people recommending checking if one isset, and if not, use a second one?

Thanks!

Mike

Link to comment
https://forums.phpfreaks.com/topic/256827-dynamic-routing/
Share on other sites

PHP_SELF and SCRIPT_NAME are out of the equation because they don't go close to providing the data that you need.

 

As for a consensus, I'm not sure there is any. Simple frameworks will likely only use REQUEST_URI as it is generally reliable, however, something more robust will check for various server specific variables such as X_REWRITE_URL and UNENCODED_URL before falling back to REQUEST_URI and then finally ORIG_PATH_INFO.

 

I'm in the process of writing a framework myself and decided to go down the simple REQUEST_URI path for now. I figure I can always add more checks latter if need be but for now REQUEST_URI is perfectly reliable.

Link to comment
https://forums.phpfreaks.com/topic/256827-dynamic-routing/#findComment-1316838
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.