darkywarkey Posted July 8, 2009 Share Posted July 8, 2009 Trying to create a more graceful approach to redirecting according to the current url. Couldn't find any function on the php.net site to pull a url. How are redirects typically handled in cases such as clicking on a page that requires you to login, then after filling out login page it redirects back to previous page being accessed? I'd like to implement something similar. Preferably without using javascript. Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/ Share on other sites More sharing options...
Philip Posted July 8, 2009 Share Posted July 8, 2009 header("Location:...");? Sorry - misread part of your question. When they visit the login page, you could have the link like: login.php?redirect=members - Then pull the redirect page by $_GET['redirect'] and act accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/#findComment-870787 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Not sure exactly what you're asking, if you're looking for the current url you can use $_SERVER['REQUEST_URI'] Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/#findComment-870793 Share on other sites More sharing options...
chronister Posted July 8, 2009 Share Posted July 8, 2009 Not sure if this will add anymore than what has already been said, but the basic process is this.... page1.php - user requests this page but it requires login... using either sessions or a $_GET var in the url, you take note of the page that they came from with $_SERVER['REQUEST_URI']. redirect happens using header('Location:XXXXXX'); to login.php On login.php you could have a hidden field to store the redirect page pulled from the url or a session var, user logs in and your script processes it and then use header() again to redirect to the stored page. Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/#findComment-870797 Share on other sites More sharing options...
darkywarkey Posted July 8, 2009 Author Share Posted July 8, 2009 Thanks, that pretty much answers it. Guess I worded my question poorly. I should have asked if there's a way to pull the previous page dynamically, but now that I think about it that wouldn't be doable on the server side. At least I wouldn't think so. Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/#findComment-870815 Share on other sites More sharing options...
cunoodle2 Posted July 8, 2009 Share Posted July 8, 2009 java script reffering page?? Quote Link to comment https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/#findComment-870816 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.