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, Link to comment https://forums.phpfreaks.com/topic/259277-get-value-after-slash-in-url/ 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. Link to comment https://forums.phpfreaks.com/topic/259277-get-value-after-slash-in-url/#findComment-1329304 Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 basename($_SERVER['REQUEST_URI']); Link to comment https://forums.phpfreaks.com/topic/259277-get-value-after-slash-in-url/#findComment-1329307 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'])); } Link to comment https://forums.phpfreaks.com/topic/259277-get-value-after-slash-in-url/#findComment-1329309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.