title: PHP SESSION array getting deleted while redirecting from one folder to another
body: <p>Okay I dont know what mistake I'm doing. I've used SESSION variables in past too without any problem but it doesnt seem to work this time.</p>
  
  <p>Here is code from my protected_page.php (page where user is redirected after login is successful).</p>
  
  <pre><code>&lt;?php if (login_check($mysqli) == true) : ?&gt;
          &lt;p&gt;Welcome &lt;?php echo htmlentities($_SESSION['username']); ?&gt;!&lt;/p&gt;
          &lt;p&gt;
              This is an example protected page.  To access this page, users
              must be logged in.  At some stage, we'll also check the role of
              the user, so pages will be able to determine the type of user
              authorised to access the page.
              &lt;/br&gt;&lt;/br&gt;
              &lt;a href="add/home.php"&gt;Add new user!&lt;/a&gt;
          &lt;/p&gt;
          &lt;p&gt;Logout &amp; return to &lt;a href="includes/logout.php"&gt;login page&lt;/a&gt;&lt;/p&gt;
      &lt;?php else : ?&gt;
          &lt;p&gt;
              &lt;span class="error"&gt;You are not authorized to access this page.&lt;/span&gt; Please &lt;a href="includes/logout.php"&gt;login&lt;/a&gt;.
          &lt;/p&gt;
      &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>The function login_check() checks weather user has logged in properly with right credentials or not. If yes, it returns true.</p>
  
  <p>There is another function namely login() which is called during login process and matches credentials with entered credentials. If true, it then stores 'username' in $_SESSION variable.</p>
  
  <p>When I click on "Add new user!" It sends me to add/home.php page, but there is o $_SESSION variable.</p>
  
  <pre><code>if (login_check($mysqli) == true) : ?&gt;
      &lt;p&gt;Welcome &lt;?php echo htmlentities($_SESSION['username']); ?&gt;!&lt;/p&gt;
      &lt;h1&gt;Add user!&lt;/h1&gt;
      &lt;?php
      if (!empty($error_msg)) {
          echo $error_msg;
      }
      ?&gt;
      &lt;ul&gt;
          &lt;li&gt;Emails must have a valid email format&lt;/li&gt;
      &lt;/ul&gt;
      &lt;form action="&lt;?php echo esc_url($_SERVER['PHP_SELF']); ?&gt;" 
              method="post" 
              name="registration_form"&gt;
          Full Name: &lt;input type='text' 
              name='fullname' 
              id='fullname' /&gt;&lt;br&gt;
          Email: &lt;input type="text" name="email" id="email" /&gt;&lt;br&gt;
          Project Name: &lt;input type="text"
                           name="project" 
                           id="project"/&gt;&lt;br&gt;
          Phone Number: &lt;input type="text" 
                                   name="phone" 
                                   id="phone" /&gt;&lt;br&gt;
          &lt;input type="submit" 
                 value="Submit"  /&gt; 
      &lt;/form&gt;
      &lt;p&gt;Logout &amp; return to &lt;a href="../includes/logout.php"&gt;login page&lt;/a&gt;&lt;/p&gt;
      &lt;?php else : echo "7"; ?&gt;
          &lt;p&gt;
              &lt;span class="error"&gt;You are not authorized to access this page.&lt;/span&gt; Please &lt;a href="../includes/logout.php"&gt;login&lt;/a&gt;.
          &lt;/p&gt;
      &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>It always prints I dont ve enough credentials to view this page.</p>
  
  <p>I also ve introduced sec_session_start() function atop both pages. (protected_page.php &amp; add/home.php). sec_session_start() is user defined custom session starting function.</p>
  
  <pre><code>function sec_session_start() {
  $session_name = 'sec_session_id';   // Set a custom session name
  $secure = SECURE;
  // This stops JavaScript being able to access the session id.
  $httponly = true;
  // Forces sessions to only use cookies.
  if (ini_set('session.use_only_cookies', 1) === FALSE) {
      header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
      exit();
  }
  // Gets current cookies params.
  $cookieParams = session_get_cookie_params();
  session_set_cookie_params($cookieParams["lifetime"],
      $cookieParams["path"], 
      $cookieParams["domain"], 
      $secure,
      $httponly);
  // Sets the session name to the one set above.
  session_name($session_name);
  session_start();            // Start the PHP session 
  session_regenerate_id();    // regenerated the session, delete the old one. 
  </code></pre>
  
  <p>}</p>
  
  <p>I don't know what I'm doing wrong this time. Must be a silly mistake. Thanks in advance. :)</p>
  
  <p>For any further details do inform me.</p>