How to restrict user to go back after logout in php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VikramShaw
Forum Newbie
Posts: 3
Joined: Sun Jul 05, 2015 3:32 pm

How to restrict user to go back after logout in php?

Post by VikramShaw »

I'm new to php and I'm building a site but the problem I'm facing is that I want to restrict the users to go back after logout. By this I mean to say that whenever user clicks on logout button it is redirecting to login page but even after logout if users click on back button it is redirecting the user to the last page they had visited which I don't want. I tried searching but didn't got any result.

Can anyone help me on how to resolve that problem and please if anyone is giving codes then please tell me where to put that code also..

Thank you..
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to restrict user to go back after logout in php?

Post by requinix »

You can't really prevent people from doing that.

What's the problem with them going back?
VikramShaw
Forum Newbie
Posts: 3
Joined: Sun Jul 05, 2015 3:32 pm

Re: How to restrict user to go back after logout in php?

Post by VikramShaw »

There are two ways of preventing that:- 1) By killing the session after users clicks on logout and 2) By removing the cache from user side(which is not recommended). But the thing is I don't know how to do it.

For security purpose I need that.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to restrict user to go back after logout in php?

Post by requinix »

So you don't mind if they go back - you just don't want to show the content? Of course they could still File > Save the page...

There are some cache headers to include to prevent caching, primarily Cache-Control and Pragma. Send those (with the appropriate values) on that page and the browser should always attempt to re-request the page, both on refresh or back button.
VikramShaw
Forum Newbie
Posts: 3
Joined: Sun Jul 05, 2015 3:32 pm

Re: How to restrict user to go back after logout in php?

Post by VikramShaw »

Sorry to say but I didn't understood what you told.
See I'm building a social networking site and the only thing which is creating prob is this.
I want if user click on logout it should redirect to login page which is working fine but after logout if they press browser back button it should not redirect to the last page they had visited rather it should refresh the login page so that they can't access the last page they had visited.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to restrict user to go back after logout in php?

Post by requinix »

Look into those headers I mentioned and make sure they get sent on each page, either by way of server configuration or by PHP's header(). They tell the browser not to cache pages. Thus when the user hits Back or whatever, the browser will request the page from your server and you can tell it to redirect.
Post Reply