title: I have an issue where $_SESSION['login_user'] is returning undefined yet the login form still works?
body: <p>So like the title says, $_SESSION['login_user'] returns undefined yet the login form still works.
  I use $_SESSION['login_user'] after login to store the persons username to use for headings ect.
  Here is the code below.</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  include('login.php'); // Includes Login Script
  if (isset($_SESSION['login_user'])) {
      header("location: profile.php"); // Redirecting To Profile Page
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Login Form in PHP with Session&lt;/title&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="login"&gt;
      &lt;h2&gt;Login Form&lt;/h2&gt;
      &lt;form action="login.php" method="post"&gt;
          UserName : &lt;input id="name" name="username" placeholder="username" type="text"&gt;
          Password : &lt;input id="password" name="password" placeholder="**********" type="password"&gt;&lt;br&gt;&lt;br&gt;
          &lt;input name="submit" type="submit" value="Login"&gt;
          &lt;span&gt;&lt;?php echo $error; ?&gt;&lt;/span&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
  session_start(); // Starting Session
  $error = ''; // Variable To Store Error Message
  if (isset($_POST['submit'])) {
  if (empty($_POST['username']) || empty($_POST['password'])) {
  $error = "Username or Password is invalid";
  }
  else{
  // Define $username and $password
  $username = $_POST['username'];
  $password = $_POST['password'];
  // mysqli_connect() function opens a new connection to the MySQL server.
  $conn = mysqli_connect("localhost", "root", "", "sports world");
  // SQL query to fetch information of registerd users and finds user match.
  $query = "SELECT Username, Password from login where Username=? AND Password=? LIMIT 1";
  // To protect MySQL injection for Security purpose
  $stmt = $conn-&gt;prepare($query);
  $stmt-&gt;bind_param("ss", $username, $password);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($username, $password);
  $stmt-&gt;store_result();
  if($stmt-&gt;fetch()) //fetching the contents of the row {
  $_SESSION['login_user'] = $username; // Initializing Session
  header("location: profile.php"); // Redirecting To Profile Page
  }
  mysqli_close($conn); // Closing Connection
  }
  
  </code></pre>
  
  <p>session.php</p>
  
  <pre><code>&lt;?php
  // mysqli_connect() function opens a new connection to the MySQL server.
  $conn = mysqli_connect("localhost", "root", "", "sports world");
  session_start();// Starting Session
  // Storing Session
  $user_check = $_SESSION['login_user'];
  // SQL Query To Fetch Information Of User
  $query = "SELECT Username from login where Username = '$user_check'";
  $ses_sql = mysqli_query($conn, $query);
  $row = mysqli_fetch_assoc($ses_sql);
  $login_session = $row['Username'];
  
  </code></pre>
  
  <p>profile.php</p>
  
  <pre><code>&lt;?php
  include('session.php');
  if(!isset($_SESSION['login_user'])){
  header("location: index.php"); // Redirecting To Home Page
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;title&gt;Your Home Page&lt;/title&gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
      &lt;link href="Main.css" rel="stylesheet" type="text/css"&gt;
      &lt;link href="Shop.css" rel="stylesheet" type="text/css"&gt;
      &lt;script src="Main.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script&gt;
          sessionStorage.setItem('status','loggedIn');
          sessionStorage.setItem('username','&lt;?php echo $_SESSION['login_user']; ?&gt;');
          sessionStorage.setItem('Fname', 't');
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="myFunctionH(); bttn();"&gt;
  &lt;section id="header"&gt;
      &lt;div class="header"&gt;
          &lt;h1&gt;Sports World&lt;/h1&gt;
  
      &lt;/div&gt;
      &lt;div class="MainMenu"&gt;
          &lt;a href="Home.php" &gt;Home&lt;/a&gt;
          &lt;a href="Shop.php" &gt;Shop&lt;/a&gt;
          &lt;a href="Contact.php"&gt;Contact Us&lt;/a&gt;
          &lt;a href="Cart.php" style="float: right"&gt;Cart&lt;/a&gt;
          &lt;input class="active button button3" id="b1" onclick="dest();" type=button&gt;
      &lt;/div&gt;
  
  &lt;/section&gt;
  
  &lt;!--
  &lt;div id=""&gt;
  &lt;b id=""&gt;Welcome : &lt;i&gt;&lt;?php /*echo $_SESSION['login_user']; */?&gt;&lt;/i&gt;&lt;/b&gt;
  &lt;b id=""&gt;&lt;a href="logout.php"&gt;Log Out&lt;/a&gt;&lt;/b&gt;
  &lt;/div&gt;
  --&gt;
  
  &lt;section id="row" &gt;
      &lt;div class="column2"&gt;
              &lt;div class="column4"&gt;
                  &lt;div class="card3"&gt;
  
                      &lt;h1&gt;Your Profile&lt;/h1&gt;
                      &lt;h4 id="name" style="margin: 0; padding: 0;" class=""&gt; Name: Thomas Shields &lt;/h4&gt;
                      &lt;h4 id="user" style="margin-bottom: 7%; margin-top: 0; padding: 0;" &gt;&lt;/h4&gt;
  
                      &lt;button onclick="myFunctionH()" class="p.dashed"&gt;Dashboard&lt;/button&gt;
                      &lt;button onclick="myFunctionH()" class="p.dashed"&gt;Orders&lt;/button&gt;
                      &lt;button onclick="myFunctionH()" class="p.dashed"&gt;Addresses&lt;/button&gt;
                      &lt;button onclick="myFunctionS()" style=" border-style: solid none solid none;" class="p.dashed"&gt;Account Details&lt;/button&gt;
  
                      &lt;div id="myDIV"&gt;
                      &lt;div class="column6"&gt;
                          &lt;div class=""&gt;
                              &lt;input type="submit" name="change_details" style="margin-top:0;" class="btn btn-success" value="Change Details"/&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;div class="column3"&gt;
              &lt;div class="card3"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  &lt;/section&gt;
  &lt;section id="row"&gt;
  
  &lt;/section&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>main.js</p>
  
  <pre><code>function bttn() {
      let elem = document.getElementById("b1");
  
      if (sessionStorage.getItem('status') === null) {
          elem.value = "Login"
      }
      if (sessionStorage.getItem('status') !== null) {
              elem.value = "View Account";
          }
      }
  
      if (sessionStorage.getItem('status') === "loggedIn") {
          let us = sessionStorage.getItem('username');
          document.getElementById("user").innerHTML = "Username:  " + us;
      }
  
  function dest() {
      if (sessionStorage.getItem('status') === null) {
          window.location.href='index.php'
      } else if (sessionStorage.getItem('status') !== null){
          window.location.href='profile.php'
      }
  }
  
  window.onbeforeunload = function(){
      sessionStorage.setItem('status',' ');
  };
  
  
  function myFunctionH() {
      let x = document.getElementById("myDIV");
          x.style.display = "none";
  }
  
  function myFunctionS() {
      let x = document.getElementById("myDIV");
      if (x.style.display === "none") {
          x.style.display = "block";
      }
  }
  </code></pre>
  
  <p>I've being trying different things for ages but i just can't get it to work.
  Note: it did work in a previous version and when comparing the versions nothing seems different...</p>
  
  <p>Cheers</p>