Current location: Hot Scripts Forums » Programming Languages » PHP » browser back button issue!


browser back button issue!

Reply
  #1 (permalink)  
Old 02-28-07, 12:27 PM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
Question browser back button issue!

Hello everyone,

i am working on a password reset page. i am sending a link to reset/change the password for the registered users through mail. whenever the user clicks on the link, hes taken to a page where he can change his password. after submitting the form, the user can click browser back button and can change the password again. i dont want this to happen. it should either give him a msg saying he has already changed his password or something like that. can anyone help me with this regard ? any logic/code wud be helpful..

Thanks.
__________________
i am still a learner and i like $this-> smilie!
Reply With Quote
  #2 (permalink)  
Old 02-28-07, 01:20 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
If you use the <body>s onunload event you can alert them that they have already changed their password. Or send them to a different page. Etc...
__________________
Jerry Broughton

Last edited by job0107; 02-28-07 at 01:28 PM.
Reply With Quote
  #3 (permalink)  
Old 02-28-07, 01:51 PM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
first of all, thanks for ur time.. umm..but i dont think u got what i was trying to say.. umm.. say i have 5.php which has 2 form elements. 1. <input type="password" name="password"> and a submit button. whenever submit button is pressed, it validates for password's length and all, then takes him to page 6, where the password is updated in the table. (6.php just has an update query). wats happening is, whenever user enters a password and clicks on submit, his password is updated. he can then use his browser's back button to get back to 5.php and change the password again. i dont want that to happen. i even redirected 6.php to some other page say 'success.php' using header, but, nothing happend !?!
__________________
i am still a learner and i like $this-> smilie!
Reply With Quote
  #4 (permalink)  
Old 02-28-07, 01:56 PM
bizzar528's Avatar
bizzar528 bizzar528 is offline
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,550
Thanks: 2
Thanked 16 Times in 15 Posts
Maybe require that they enter their old password in conjunction with the new one. Then, on page6, run the logic to make sure they aren't setting it to a different password without validating the current one.
Reply With Quote
  #5 (permalink)  
Old 02-28-07, 05:00 PM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
its a password reminder page. a user will come to this page only if he doesnt remember his password.
__________________
i am still a learner and i like $this-> smilie!
Reply With Quote
  #6 (permalink)  
Old 02-28-07, 05:11 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
In the <head> in 6.php insert this code and try it.
Code:
<script>
function login_here()
{
 alert("To request your password again\nYou must login again.");
 location.href = "login.php";
 }
</script>
And be sure to have a <body> tag like this:
Code:
<body onunload="login_here();">
Change "login.php", to the page you want to goto.
__________________
Jerry Broughton

Last edited by job0107; 02-28-07 at 05:14 PM.
Reply With Quote
  #7 (permalink)  
Old 02-28-07, 05:22 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I wouldn't rely on Javascript for things like this.

But why is that bad anyway? Why can't he change the password again?


You could add a field to the users table, and when you send the email, generate a random code and send it with the email to the user and add the value to the field in the database. So the link looks like this more or less:

http://example.com/forgotpass.php?hash=hIkw8302


Then before updating the password, you check if the value in the field matches the one given in the URL.

If it does, update the password and set the value in the database field to 0 for example.

Make sure that the user can't add the 0 manually to the URL and change the pass whenever he wants to.

Last edited by Nico; 02-28-07 at 07:36 PM. Reason: Typo.
Reply With Quote
  #8 (permalink)  
Old 02-28-07, 07:19 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Nico is right, using the database look-up would be alot more versitle and secure.
__________________
Jerry Broughton
Reply With Quote
  #9 (permalink)  
Old 02-28-07, 09:46 PM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
thank you all.. i am doing the same thing what nico has said.. but while changing password, i am not updating the table(setting the value to 0 as he said here). but i am adding a new row to the table. (the table is basically a log table to know what the consumer is upto !).. whenever a user requests for password, before sending him the mail, i am inserting a row in the database(with some random number and his password request time). when he clicks on the link, i am validating if that random number exists in the table. if it does, then i m showing him the password page. after changing the password, i am not updating the table, but i am inserting a new row(saying, the user changed his password @ this time).
i m validating if the user has already changed the password by doing the following.
PHP Code:

$id=$_GET['id'];  // from the query string

$sql mysql_query("select * from user_logs where consumer_id='$id'",$conn);
$rows=mysql_num_rows($sql);
if(
$rows 1){   // if he has requested for the pass and has changed it. 
//There will be only one entry if the user has just requested for the pass ! 
//if there are more then one entry, then he has changed his password.
echo "You have already used this link to change your password.";
exit;
} else {
// show password field
//submit

actually, whenever i change my password and click on back button, it shows the password field again! But when i refresh the page, it gives me the message saying "You have already used this link to change your password." why is that so ?

Thanks.
__________________
i am still a learner and i like $this-> smilie!
Reply With Quote
  #10 (permalink)  
Old 03-01-07, 02:12 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It's cause your page is being cached. Try sending these headers on the page.

PHP Code:

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' gmdate('D, d M Y H:i:s') .' GMT');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Cache-Control: post-check=0, pre-check=0'false); 
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 Open a New Browser Window & Click a Submit Button Wildhalf JavaScript 3 12-08-06 03:34 PM
how to disable browser's back button after logout shaky ASP 7 08-18-06 07:37 AM
Replace Back Button eddyvlad JavaScript 1 07-28-06 01:12 AM
Using the Back Button and the Close Button mdgibson Hot Scripts Forum Questions, Suggestions and Feedback 1 09-29-05 12:41 AM


All times are GMT -5. The time now is 05:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.