I'm using PHP, I wanted to know if a user lands on a certain page, and they have to login or signup to be able to do actions like commenting or rating etc. I wanted to able to take the user back to that same page after they login.
I was thinking to use the PHP get function and pass the URL, I'm not sure that's the best way to do it.
Presumably your login fields are in an html form. When you're constructing the form, put the current URI in a hidden input field, then you have the information available to you when you want to perform the redirect after the POST data has been submitted.
I don't typically use PHP without a framework, but here are some resources that will help you get this information:
http://www.webcheatsheet.com/PHP/get_current_page_url.php
How can I get the current page's full URL on a Windows/IIS server?
Basically, it goes like this:
$current_url = "http://" .$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];
But if you are using https, you have to change that string accordingly.
An alternative is to redirect them back to $_SERVER['HTTP_REFERER']. One thing to take into consideration is that the browser can choose not to send the Referer URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With