CodeIgniter Forums
[RedirectClass] toReferrer - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: [RedirectClass] toReferrer (/showthread.php?tid=91150)



[RedirectClass] toReferrer - christianberkman - 06-24-2024

In my project is is likely users will open multiple tabs but continue navigating on the original tab. In this case, using redirect()->back() produces unexpected behavior. Example

  • user opens /list/
  • user opens /list/item/1 in a new tab (in background)
  • user posts form on /list
  • controller handles form posts and does a
    Code:
    redirect()->back()

  • user is now redirected back to /list/item/1 since it is the last visited url in the session
The behaviour of
Code:
redirect()->back()
is well documented and I understand the choice to use the session for safety.

However, would there be enough of a use case to add  a
Code:
redirect()->toReferrer()

function to cover the case I just described? Of course, this would be not much more than a convenience function as the functionality can already be achieved with other functions from the framework.

I would be happy to open a PR.


RE: [RedirectClass] toReferrer - kenjis - 06-24-2024

HTTP_REFERER is not reliable.
So if you want to use it, redirect()->to($referer) by yourself.


RE: [RedirectClass] toReferrer - kenjis - 06-24-2024

There is no need to use back() or referer in the first place.
You can just specify the URI in the controller.