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! 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"], "?") 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? 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. 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! 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
Archived
This topic is now archived and is closed to further replies.