Some sites have this feature that when you click on a link that requires a login first, they automatically go to a login form. But, after login they get redirected to the page that they were previously viewing. How does the page know where the user is coming from? Where is this URL stored? In the $_GET or $_Session or something else?
You store the link in a hidden textbox in login page and whenever you get login just fetch the link from hidden text and rederect to the page using header('Location: Redirect PageURL')
You could use GET or SESSION but as Subikar says a hidden POST value is probably best. No real problems with GET that I know about but SESSION can lead to difficulties when a user has multiple tabs/windows open browsing the same site.
Yes, You can accomplish this task with GET,Post or Session variable easily...No great coding required for this task....
How to use $_POST when the pages are different? Say A is the page i'm visiting, with a link on it to page B which requires a login first. The login page is on page C. Where can I create a hidden textbox the surfer gets redirected from page C to B ?
lets suppose you want user to be logged in before viewing news.php, redirect user to login.php?lastpage=news.php Now on login.php, save the page name in session, as $_SESSION['lastpage'] = $_GET['lastpage']; When user logged in successfully, redirect him/her to old page using following code, header("location:" . $_SESSION['lastpage']); Hope this helps.
Suggestion of "designcode" is good but I think for this type of things you shouldn't use $_SESSION because if cookie is disable then it will not work. But disabling of COOKIE is rare cases but you must keep in mind of this.
$_SESSION is just for example, if you are running a big application, I can bet you won't be relying on PHP's $_SESSION thing, you will be handling session yourself (using DB or whatever), won't you ? Anyway cookies are disabled rarely these days, because i think most peoples are now aware that cookies can't harm your PC, only they can make you fat
Thats right designcode in this modern generation no one want to be fat any way good suggestion. . fatabbot You can implement the system according to designcode suggestion too.