0

I have created an login system with form which use POST method. This POST send information to the login.php which included into the index php. In the login.php if the username and password correct a few jQuery code change some things (add menu items) on the index.php. My problem is that when I want to refresh the page the Firefox always send a confirm message (To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.). I have red about it and I know that this problem is about I use POST method to send data. Some people suggested to use GET method, although the message do not appear but the data don't send as well. Could you suggest a solution (if it is exist)? Thank you in advance for your help.

My php code:

 $query1 = pg_query($conn, "SELECT * from users WHERE password = '$pswd' and name='$username' ");


$arr_1 = pg_fetch_all($query1);


$name_lenght= strlen($arr_1[0][name]);
$pswd_lenght= strlen($arr_1[0][password]);

if ($name_lenght > 0 && $pswd_lenght > 0){


 $_SESSION ['user'] =  $_POST['user'];
 $_SESSION ['password'] = $_POST['password'];


echo "<script>  
$('#manu1').removeClass('hide').addClass('show');
$('#manu2').removeClass('hide').addClass('show');
$('#manu3').removeClass('hide').addClass('show');
</script>";
bummm26
  • 159
  • 3
  • 17
  • a simple solution for that is to use a transition page and a redirection. Let's say that the page `login` is the target of your form. `login` treats the form data, sets the user session (cookies or such) and redirects to your page, let's call it `user`. This done, when you refresh, you refresh `user` and not `login`, which was not bound to form data. So the browser don't ask you to submit it again – Kaddath Jul 03 '17 at 09:11
  • https://en.wikipedia.org/wiki/Post/Redirect/Get – CBroe Jul 03 '17 at 09:16

1 Answers1

0

The script that processes the form should send a redirect to the page that should display after you're logged in, instead of displaying the output itself. This disconnects the new page from the form submission, so it won't ask you if you want to resubmit the form data.

$query1 = pg_query($conn, "SELECT * from users WHERE password = '$pswd' and name='$username' ");
$arr_1 = pg_fetch_all($query1);
if (!empty($arr_1)) {
    $_SESSION ['user'] =  $_POST['user'];
    $_SESSION ['password'] = $_POST['password'];
    header("Location: welcome.php");
    exit();
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I put this code into my If statement, and although the message do not appear but the in the statement the commands dot not run.I edited my post with the php. Where should i put this code? – bummm26 Jul 03 '17 at 09:35
  • It worked before I logged in, but I i logged in my if statement (`if ($name_lenght > 0 && $pswd_lenght > 0)`)do not want to execute, so fr example the logout button don't appear via my jQuery. – bummm26 Jul 03 '17 at 09:46
  • Why are you testing the length? Just test if the query returns any rows, like in my answer. – Barmar Jul 03 '17 at 09:48
  • Your solution is worked for me! Thank you for your help! – bummm26 Jul 03 '17 at 10:21