You are invited to Log in or Register a free Frihost Account!

How can I disable the back button of my browser?

Hi! i'm currently developing a system using php and mysql. I ony have 1 problem left. How can I disable the browser's back button to prevent the user who have logged out from going back to the previous page? I have tried the

header ("Location: PAGENAME");

but an error telling me that the header was already been sent appears. PLease help. Thank you.

By the way, im using Internet explorer.
In order to use the header() section, you must call the function before any output is sent to the user (because that's when headers are sent). Make sure you open your <?php code block at the very beginning of the file and don't echo/print any output before the header() function.

Also, how are you using the header function? Perhaps I'm misunderstanding you, but preventing the user from going backwards isn't the best way to keep a user from logging out and then going back to protected information. When they are logged in, there should be some info (cookie/session data) that says they are logged in, and that should be canceled out when they are logged out. Then, if that data shows them to be logged out, the protected page should redirect the user using the header() function.

But, perhaps that's what you're already trying to do and I was a bit confused by your wording.

If you can't figure it out, paste your source code here and someone can probably find the point where you're outputting some data.

- Walkere
I don't think there *is* a way of disabling the user's back button - it's the user's, not yours. As stated, they won't be able to get back into protected content anyway if they're logged out, so you needn't worry.
There is a way if the user wants to work with you: after the user logs off, open the new page in a new window (logout->target=new) and use Javascript to close the old one. ("javascript:window.close") The browser will ask the user if he is sure he wants to close the window.

Another, more neat way, is to open the safe part of your application in a new window when a user logs in. You could even use javascript to give this window no buttons or toolbar or whatsoever. When the user logs out, the window closes itself and returns to the page the user was before he logged in.

Does this help?
Hey guys! thanks for all these replies. I just presented the system that I created yesterday. Before I present I was required to debug, and configure the server (Which is up to you to figure if the server needs to be configured). I had a 100. so far the highest (for no one thought that the server was not configured). Thanks for all these replies once again. I really appreciate it because it made me feel challenge to do new thing like disabling the back button.

this is the code that i used:


Its not that impressive but it works. put it on the page before the logout page.

don't u dare use javascript or even AJAX for ANY authentication purposes EVER... it's the most risky thing to do. Use a good PHP/MySQL combo along with wise usage of sessions (or psuedo sessions) for the authentication system. Breaking the back button is of no use. If they know the address of the previous page, they can paste it in their address bar and go there too in case you EVEN manage to disable the back button, which, for all practical purposes, you won't be able to do Very Happy
Related topics
751 Useful Windows XP Files
do you like my site design ?
Need help
The noob needs help/Plz
Simulating the back button
TrendyFlash Site Builder 1.0
Firefox website,
Making your own web browser
JS Disable Button.
Disable Sound in Browser...
How to expired a page so a user cannot press back button ?
Cancel Button?
Compose an algorithm to disable a button?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.