Jump to content

How to dynamically get the current URL?


darkywarkey

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/165144-how-to-dynamically-get-the-current-url/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.