SyncViews Posted December 17, 2007 Share Posted December 17, 2007 How can I get the url for the current page in php? I tried these but none returned the exact url $_SERVER['SCRIPT_NAME'] $_SERVER['PHP_SELF'] __FILE__ I just want it to to just get the same url as dsiplayed in the user adress bar.. (includeing the domain and ?myvar = value etc). I'd also rather this can work from within an included file and still returnt he correct url) Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 17, 2007 Share Posted December 17, 2007 You can use $_SERVER['REQUEST_URI'] for that. Edit: That won't get the entire URL though. You'll need to combine some different variables like this: <?php switch($_SERVER['SERVER_PORT']) { default: case 80: $url = 'http'; break; case 443: $url = 'https'; break; } $url .= '://'.$_SERVER['SERVER_NAME'].(!in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? ':'.$_SERVER['SERVER_PORT'] : null).$_SERVER['REQUEST_URI']; echo $url; ?> Quote Link to comment Share on other sites More sharing options...
SyncViews Posted December 17, 2007 Author Share Posted December 17, 2007 that didn't return the entire url though. just the bit that comes after the domain (eg"/forums/index.php/topic,172438.0.html") I want a way to get the domain as well so when I move the site onto the internet I don't have to go through and change stuff like that... (so I want "http://www.phpfreaks.com/forums/index.php/topic,172438.0.html" rather than the above) Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 17, 2007 Share Posted December 17, 2007 I edited my post just before you replied Quote Link to comment Share on other sites More sharing options...
SyncViews Posted December 17, 2007 Author Share Posted December 17, 2007 ah that works thanks 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.