Using php, how am I able to accomplish this? Ex:
1.) There are a total of let's say 5 pages (A, B, C, D, E) any user can view (either logged in or out)
2.) User X is viewing page (C) and is not logged in
3.) User X logs in on page (C) and is logged into that same page (C) that he/she is viewing rather than being redirected to the home page
I know how to make it where a user is redirected to the home page when any user logs in on any page, but I do not desire this and is something my users do not want - I would like it where any user can log in on whatever page they are viewing and it stays on that page for them rather than being redirected.
This is what I have for a user to login and be redirected with, but have no idea how to make it work for users being able to stay on whatever page the user is viewing when they login.
PHP
header("Location: index.php");
Is there more that is needed to allow users to stay on same page they are viewing when they login? Or is there a simple solution to this that I just can't seem to find using only that 1 line of code above?
I've read tons of tutorials/blogs/forums, etc...but couldn't find a definite answer anywhere. I did come across 'PHP_SELF' but have no idea how to implement that at all and php.net doesn't really have a clear solution to how to use it - (or at least from what I read)...Any help would be much appreciated.
SOLVED: --> Thank you for your help Thinkswan
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
header("Location: $current_url");
UPDATE: --> A question that stems from the initial question
From what you provided above as the correct format, could we possibly take that a bit further? For example:
Same rules apply as previously mentioned.
1.) If User X is currently not logged in on page (C), and let's say page (C's) URL reads http://www.example.com/members.php
, and there is a div container he/she clicks on that page, another bigger div container opens.
2.) Of Which the URL now reads http://www.example.com/members.php#registered_members
3.) While that is open, the User X decides to now log in. Is there a way to make it where once the User X logs in it stays on that same page with that bigger div container open? As of right now, the div container collapses once the User X logs in, but IS logged in on the same page.