I am new to this and I am learning, but I have a problem that I can not solve.
I have a variable called $ result where it collects all the information from the database when you log in, but I need to update it every time you update or access a web page.
The way I have it is as follows:
- Action of the login button:
<form class="nav-login-form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
- Web pages:
<?php
if(isset($_POST['login'])) {
include 'php/login.php';
}
?>
- Login.php file
include 'MySQL-conn.php';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (!$conn) {
die("Conexion fallida: " . mysqli_connect_error());
}
$NickEmail = $_POST['nick-email'];
$Password = $_POST['password'];
if ($result = mysqli_query($conn, "SELECT Nick, Email, Password, Rank, Coins FROM accounts WHERE Nick = '$NickEmail' OR Email = '$NickEmail'")) {
$row = mysqli_fetch_assoc($result);
$hash = $row['Password'];
if (password_verify($_POST['password'] , $hash)) {
$_SESSION['logged'] = true;
$_SESSION['Nick'] = $row['Nick'];
$_SESSION['Email'] = $row['Email'];
$_SESSION['Rank'] = $row['Rank'];
$_SESSION['Coins'] = $row['Coins'];
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60);
echo "<style>div.successful-login {display: inline;}</style>";
From this code when you log in, I want to make a code for the reload of the variable $ result and at the same time you overwrite the variable $ _SESSION.
The code of the button is in all the pages because I have a login form in the nav of each page, therefore the first 2 codes are in all the pages. And the code of the login.php file is that, only the part where the MySQL database reads, which is what I need to reload, to $ result.
Any solution? Whatever it is.