开发者

Changing the browser back button to go back twice

I have this web application which does the following as standard to all websites

  • Users browse to any page on the website
  • They click on login link on header from any page
  • Visit login page and then login and get directed to their logged in page
  • IF user then hits back button they get to login page and that redirects to home (because they are already logged in).

How do I change at javascript or php level for the following

  • Users browse to any page on the website
  • They click on logi开发者_JAVA百科n link on header from any page
  • Visit login page and then login and get directed to their logged in page
  • IF user then hits back button they will get to the page they visited just before the login page was seen.

Thanks


There are a few ways to do this, the easiest: 1. Change the way your login process script redirects, if you change the location header then the web browser will ignore that page when the user goes back. In php it's as easy as

header("Location: http://www.google.com");

or 2.Use An AJAX login system, so rather than going from home->loginpage->profilepage you could have an in-page popup box that allows the user to login inside the homepage.

Either way, as an ease of use feature, you should probably send the user back to the homepage after login, and then there is no need to use the back button - on the new home page simply have "Welcome Bob, Profile Links Merged With Home Page, etc" added when a user is detected.

Hope that helps :)


there isn't a way to change the behaviour of the back button.

why don't you change the logic so that when the user clicks login the current page is passed through (as a parameter or use referrer) and then used to redirect once the user has logged in.


You probably need use a header redirect in php to do this rather than try to use the back button.


You will just need to add some code to your login script that:

A) Checks if a user is logged in or not (probably using sessions)

if they are logged in redirect to the home page , If they are no logged in then load up the login page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜