melting_dog Posted January 4, 2012 Share Posted January 4, 2012 Hey guys, Was wondering if someone could point me on the right path here. I am able to get the page URL using: $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; But was wondering if there was a way to drop the PHP variables attached to the URL. e.g. mysite.com/catalogue/?item=23 becomes mysite.com/catalogue/ Can anyone help me out? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254333-get-page-url-minus-php-variables/ Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 Use strtok on the REQUEST_URI: strtok($_SERVER["REQUEST_URI"], "?") Quote Link to comment https://forums.phpfreaks.com/topic/254333-get-page-url-minus-php-variables/#findComment-1304105 Share on other sites More sharing options...
melting_dog Posted January 4, 2012 Author Share Posted January 4, 2012 Thanks requinix, I also got it working using $url = dirname($url); but would I be right in saying your way is the more 'pure' way? Quote Link to comment https://forums.phpfreaks.com/topic/254333-get-page-url-minus-php-variables/#findComment-1304118 Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 dirname() will only work in some of the situations. For example, it won't work with URLs like "/path/to/file.php?query_string". strtok(), or some similar method, will work on every URL. Quote Link to comment https://forums.phpfreaks.com/topic/254333-get-page-url-minus-php-variables/#findComment-1304122 Share on other sites More sharing options...
melting_dog Posted January 5, 2012 Author Share Posted January 5, 2012 Yeah I switched it over. I t does work better. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254333-get-page-url-minus-php-variables/#findComment-1304436 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.