Witam, chciałbym się dowiedzieć w jaki najbardziej optymalny sposób, można zrobić, tak aby co każde odświeżenie strony (f5) PHP pobierało ("Odświeżało") rekordy z bazy danych, bo kiedy np. zmienię nazwę użytkownika z poziomu mojego systemu logowania, to nowa będzie wyświetlania dopiero po ponownym zalogowaniu.
<?php
session_start();
require_once('config.php');
$err_pdm = false;
$err_tsh = false;
$err_tln = false;
$err_ilc = false;
$wrn_sap = false;
$err_am = 0;
$old_pass = $_SESSION['user_pass'];
$pass_raw = $_POST['new_password'];
$pass_raw_r = $_POST['r_new_password'];
if ($pass_raw != $pass_raw_r) {
$_SESSION['passch_dont_match'] = $passchange_pass_dont_match;
$err_pdm = true;
}
if (strlen($pass_raw)<3) {
$_SESSION['passch_too_short'] = $passchange_pass_too_short;
$err_tsh = true;
}
if (strlen($pass_raw)>60) {
$_SESSION['passch_too_long'] = $passchange_pass_too_long;
$err_tln = true;
}
if (!preg_match($pass_pattern ,$pass_raw)) {
$_SESSION['passch_illegal_char'] = $passchange_pass_illegal_character;
$err_ilc = true;
}
if (password_verify($pass_raw, $old_pass)) {
$_SESSION['passch_same_as_previous'] = $passchange_pass_same_as_previous;
$wrn_sap = true;
}
if ($err_pdm == true || $err_tsh == true || $err_tln == true || $err_ilc == true) {
$_SESSION['passch_fail'] = $passchange_fail;
header('Location: pass_change.php');
} else {
$pass_hash = password_hash($pass_raw, PASSWORD_DEFAULT);
$u_id = $_SESSION['user_id'];
$update_pass = "UPDATE `users` SET `u_pass` = '$pass_hash' WHERE `users`.`ID` = '$u_id' ";
if ($update_pass_result = $connection_1->query($update_pass))
{
//Log builder
if (!isset($_SESSION['debug_log_1'])) {
$_SESSION['debug_log_1'] = $passchange_succes;
header('Location: user_panel.php');
} elseif (!isset($_SESSION['debug_log_2'])) {
$_SESSION['debug_log_2'] = $passchange_succes;
header('Location: user_panel.php');
} elseif (!isset($_SESSION['debug_log_3'])) {
$_SESSION['debug_log_3'] = $passchange_succes;
header('Location: user_panel.php');
} elseif (isset($_SESSION['debug_log_1']) && isset($_SESSION['debug_log_2']) && isset($_SESSION['debug_log_3'])) {
unset($_SESSION['debug_log_3']);
$_SESSION['debug_log_3'] = $_SESSION['debug_log_2'];
$_SESSION['debug_log_2'] = $_SESSION['debug_log_1'];
$_SESSION['debug_log_1'] = $passchange_succes;
header('Location: user_panel.php');
} else { echo 'something done wrong'; }
if ($wrn_sap == true) {
//Log builder
if (!isset($_SESSION['debug_log_1'])) {
$_SESSION['debug_log_1'] = $passchange_pass_same_as_previous;
header('Location: user_panel.php');
} elseif (!isset($_SESSION['debug_log_2'])) {
$_SESSION['debug_log_2'] = $passchange_pass_same_as_previous;
header('Location: user_panel.php');
} elseif (!isset($_SESSION['debug_log_3'])) {
$_SESSION['debug_log_3'] = $passchange_pass_same_as_previous;
header('Location: user_panel.php');
} elseif (isset($_SESSION['debug_log_1']) && isset($_SESSION['debug_log_2']) && isset($_SESSION['debug_log_3'])) {
unset($_SESSION['debug_log_3']);
$_SESSION['debug_log_3'] = $_SESSION['debug_log_2'];
$_SESSION['debug_log_2'] = $_SESSION['debug_log_1'];
$_SESSION['debug_log_1'] = $passchange_pass_same_as_previous;
header('Location: user_panel.php'); }
}
} else {
$_SESSION['passch_fail'] = $passchange_fail;
header('Location: pass_change.php');
}
}
$connection_1->close();
?>
(To akurat jest skrypt do zmiany hasła)
Z góry dziękuje za pomoc/sugestie.