I have strange problem. I created a site with login/register/profile functions, but the problem is when i go to my profile for example it says
Hello, John Doe.
Then i logout and login with different account(for example lets say the name is Mark Smith), and then when i go to profile.php it still says
Hello, John Doe untill i reload the page (F5) than it changes to
Hello, Mark Smith.
What is the problem, in my logout file i destroy every session.. Code:
<!DOCTYPE html>
<html>
<head>
    <title>MyProject: Profile Page</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
    /* css here so i don't have to create specific file only for bg. */
    body 
    {
        background: url(images/index-body.jpg) no-repeat center center fixed;
        position: absolute;
        top: 0;
        left: 0;
        min-height: 100%;
        min-width: 100%;
        background-size: cover;
    }
    </style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="welcome.php">MyProject: Welcome</a>
        </div>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="welcome.php"><span class="glyphicon glyphicon-home"></span> Home</a></li>
        <li><a href="profile.php"><span class="glyphicon glyphicon-user"></span> My Account</a></li>
        <li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
    </ul>
    <form class="navbar-form navbar-right" action="search.php">
        <div class="form-group">
            <input type="text" class="form-control" placeholder="Search by keyword" name="search_prototype">
        </div>
    </form>
  </div>
</nav>
<br><br><br><br><br>
<div class="container">
    <div class="jumbotron">
    <?php
    session_start();
    ob_start();
    require 'db.php';
    if(!isset($_SESSION['logged_in']))
    {
      header("location: index.php");
      exit();
    }
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        if(isset($_POST['update_submit']))
        {
            if(!empty($_POST['update_name']) && !empty($_POST['update_lastname']) && !empty($_POST['update_email']) && !empty($_POST['update_aboutme']))
            {
                $first_name = $mysqli->escape_string($_POST['update_name']);
                $last_name = $mysqli->escape_string($_POST['update_lastname']);
                $old_mail = $mysqli->escape_string($_SESSION['email']);
                $email = $mysqli->escape_string($_POST['update_email']);
                $about_me = $mysqli->escape_string($_POST['update_aboutme']);
                $mysqli->query("UPDATE users SET name='$first_name', lastname='$last_name', email='$email', aboutme='$about_me' WHERE email ='$old_mail'");
                $_SESSION['suc_message'] = "Your account has been updated!";
                header("location: profile.php");
                exit();
            }
            else
            {
                $_SESSION['error_message'] = "You can't leave anything blank!";
                header("location: profile.php");
                exit();
            }
        }
    }
    $email = $mysqli->escape_string($_SESSION['email']);
    $result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
    if($result->num_rows > 0)
    {
    $row = $result->fetch_assoc();
      echo '
      <div class="media-left">
          <img src="images/avatar_Test.png" class="media-object" style="width:110px">
      </div>
      <div class="media-body">
          <h2 class="media-heading">', $row['name'], ' ', $row['lastname'], '</h3>
          <small>Last active: ', $row['lastlogin'], '</small><br>
          <small>Register date: ', $row['register_date'], '</small>
     </div>
      <br><button data-toggle="collapse" class="btn btn-info" data-target="#profile_about">About me</button> 
      <button data-toggle="collapse" class="btn btn-info" data-target="#profile_contact">Contact</button> 
      <div id="profile_about" class="collapse"><br>', $row['aboutme'], '</div>
      <div id="profile_contact" class="collapse">
          <small><br>Email address: ', $row['email'], '</small><br>  
      </div>
      <br><br>
      <div class="alert alert-success">
        <span class="glyphicon glyphicon-edit"></span>  You can edit your profile data by changing the informations below
      </div>
      ';
      if(isset($_SESSION['error_message']) AND !empty($_SESSION['error_message']))
      {
          echo '
          <div class="alert alert-warning alert-dismissible" id="myAlert">
              <a href="#" class="close">×</a>
              <strong>Error!</strong> ' . $_SESSION["error_message"] . '
          </div>
          ';
          unset($_SESSION['error_message']);
      }
      if (isset($_SESSION['suc_message']) AND !empty($_SESSION['suc_message']))
      {
          echo '
          <div class="alert alert-warning alert-dismissible" id="myAlert">
              <a href="#" class="close">×</a>
              <strong>Success!</strong> ' . $_SESSION["suc_message"] . '
          </div>
          ';
          unset($_SESSION['suc_message']);
      }
      echo '
      <form method="POST">
        <input type="text" id="ex2" class="form-control" value="', $row['name'], '" aria-describedby="sizing-addon1" name="update_name"><br>
        <input type="text" id="ex2" class="form-control" value="', $row['lastname'], '" aria-describedby="sizing-addon1" name="update_lastname"><br>
        <input type="email" id="ex2" class="form-control" value="', $row['email'], '" aria-describedby="sizing-addon1" name="update_email"><br>
        <textarea class="form-control" rows="5" name="update_aboutme" id="comment" placeholder="', $row['aboutme'], '"></textarea>
        <br><br><input type="submit" name="update_submit" class="btn btn-info" value="Save"> <button data-toggle="collapse" class="btn btn-info" data-target="#profile_change_password">Change password</button> 
      </form>
      <div id="profile_change_password" class="collapse">
        <form method="POST">
          <input type="password" id="ex2" class="form-control" aria-describedby="sizing-addon1" name="update_name"><br>
          <input type="password" id="ex2" class="form-control" aria-describedby="sizing-addon1" name="update_lastname"><br>
          <br><br><input type="submit" name="update_submit" class="btn btn-info" value="Save">
        </form>          
      </div>
      ';
    }
?>
</div>
    <p>Website created by Cadilab.</p> 
</div>
<script>
$(document).ready(function()
{
    $(".close").click(function()
    {
        $("#myAlert").alert("close");
    });
});
</script>
 
    