954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to disable brouser back.

I want help.
what i do:I creat three pages 1. login.php, 2. welcome.php, 3.change password.php.
when we login(right Id & P/W) welcome.php will open,On that page i have put two option
i. Logout, ii.change password.,on clicking on Logout we will logout to enter again we have to enter password.As session is distroyed.

Problem: On welcome.php page when I logout then sesstion is dertroyed so we can not go back. welcome page when I click on back button(on brosure) it come on login page and on click on forward botton it come on welcome page.But i want ones it come on login page without without entering Id & password it should not come on welcome page as in logout condition.

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

you could use javascript to disable back i think but its not secure as they can just disable java.

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

I don't know too much about javascript,so plz tell me some script if u know for this.

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

I find one script that is

but it disable back button for all pages.

anyone have batter idia.if any then plz tell me.

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

i am trying to understand exactly what you mean. so you don't want people to go back to welcome.php after logout. is that what you are saying?

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Hi Ajay Babu

According to me, you should just use session with proper understanding, I think your code write properly. Just make sure the use of session...

Thanks
Nishit Soni
[email]nishit_0627@yahoo.co.in[/email]

nishit_soni
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

yes kkeith29,what you understand that is right.and I have got the solution for that there is javascript which slove my problem that scripte is.

<code>&lt;Script&gt;
window.history.forward(1);
&lt;/Script&gt;</code>


but still i m looking for batter solution
now I want something like yahoomail,on which after login ones if we come on login page(without doing logout) then we have to login again.

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

Soniji thanks for suggestion.
I read basic of session and I m using that,as I do logout session get distroyed.but I don't know how to distroy session when user come on privious page(i.t. loginpage) so if u have some idea about that then plz help me.

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

try this.

Login page -

<?php
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
session_destroy();
}
else {
   //Put login script here
}
?>
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

thanks kkeith
I try this code but still problem is not slove,Do u have any other idea then plz suggest me.plz Tell that how can we handal event by windows object in php.
try this.

Login page -

<?php
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
session_destroy();
}
else {
   //Put login script here
}
?>
ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

well, what exactly was the problem. did you change 'username' and 'password' to your session name for those. also i didn't think about this before but when the session is destroyed the page has to be refreshed before the logout will be successful. maybe after the session is destroyed, have the page refresh

echo '<meta http-equiv="refresh' content="0">';


this should work. it did for me

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

First, do not disable my back button. It's 2nd on my list of most hated website activities. (1st is opening new browser windows.)

Ok, now to try to understand what you're trying to do: If you want to prevent a user who logged out from seeing the information on a previous user's welcome.php page, your best bet is to tell the browser the page is out of date and needs refreshed. That way, the browser won't load the page from cache and instead load the page from the server.

I think using a "META" tag with the option "expires" (Search for "META expires" and see what comes up) is the way to go here.

Puckdropper
Posting Pro
500 posts since Jul 2004
Reputation Points: 23
Solved Threads: 23
 

thanks kkeith u help me lot.I note two different thing about (gmail yahoomail)that gemail has disable back brouser as i have done in my code.But as i tould that on yahoo when we login our mail box get openand,and when we click on back button, then it comes on login page but on click forward button it will ask for login id password again for opening our mail box,here i was wrong bcoz, in yahoo when I login my mail box get open,and we click on back button, then it comes on login page and on click forward button again it will go to mail box.
So I thing what I want that is not posibal but still i will try to find some option.anyways thank you again.

well, what exactly was the problem. did you change 'username' and 'password' to your session name for those. also i didn't think about this before but when the session is destroyed the page has to be refreshed before the logout will be successful. maybe after the session is destroyed, have the page refresh

echo '<meta http-equiv="refresh' content="0">';


this should work. it did for me

ajay_tabbu
Junior Poster in Training
52 posts since Feb 2007
Reputation Points: 24
Solved Threads: 0
 

i was just thinking about it and i thought you might be able to use page views as an option.
use a session variable to hold the number and when someone visits a page the count increases. if the count goes above 2 then logout will happen. i have never tested this so i have no idea if it works, but i think it might.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You