farnoise Posted March 19, 2012 Share Posted March 19, 2012 Hi There, I am trying to this trick with PHP that get the last Value of the URL that the user enters in the Address bar in the browser (Not that that this is not a form) and use that value. for example I have a index page that starts with the code to do trick, then your comes to my website www.abcded.com/username So what I need to do is take the value which in this case is "Username" so I can use it, and as you know in normal case it will look for the folder called username under my root folder. Thanks, Quote Link to comment Share on other sites More sharing options...
seanlim Posted March 20, 2012 Share Posted March 20, 2012 I don't think this can be achieved by PHP alone. As you mentioned, in the normal case, it will look for a folder (a file would probably do too). If that fails, your server will probably throw a 404 error without calling any of your PHP scripts. Therefore, I think a PHP-only solution doesn't exist. However, this can definitely be accomplished using a .htaccess file and a RewriteRule. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 basename($_SERVER['REQUEST_URI']); Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 Although, if it is possible that the user may type in the index.php and you always want the parent folder, then this would work as well $root_folder = basename($_SERVER['REQUEST_URI']); if(substr($root_folder, -4) == '.php') { $root_folder = basename(dirname($_SERVER['REQUEST_URI'])); } Quote Link to comment 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.