dmikester1 Posted February 10, 2012 Share Posted February 10, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256827-dynamic-routing/ Share on other sites More sharing options...
trq Posted February 10, 2012 Share Posted February 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256827-dynamic-routing/#findComment-1316838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.