Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.