title: PHP Session check not working when i redirect from another page
body: <p>I have a password check function which sets the session variable and redirects to <code>dashboard.php</code></p>
  
  <pre><code>&lt;?php
  session_start();
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
  // username and password sent from Form
  $myusername=$_POST['username']; 
  $mypassword=$_POST['password']; 
  
  
  
  
  if($myusername=="admin" &amp;&amp; $mypassword=="admin")
  {
  
  $_SESSION['login_user']=$myusername;
  header("location: dashboard.php");
  }
  else 
  {
  echo "Your Login Name or Password is invalid";
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Dashbord.php checks for the session variable like this </p>
  
  <pre><code>&lt;?php 
      session_start();
      $user_check=$_SESSION['login_user'];
      if(!isset($user_check))
      {
         header("Location: http://www.none.com/dashboard/login.php");
      }
  ?&gt;  
  </code></pre>
  
  <p>In the dashboard I have several links to php files that employs the same thing to check for session.</p>
  
  <pre><code>&lt;?php 
      session_start();
      $user_check=$_SESSION['login_user'];
      if(!isset($user_check))
      {
         header("Location: http://www.none.com/dashboard/login.php");
      }
  ?&gt; 
  </code></pre>
  
  <p>But when i click on the dashboard links,i get redirected to the login page. But if i manually navigate to the link, I can access the page.I tried clearing the session using:</p>
  
  <pre><code>&lt;?php 
  session_start();
  unset($_SESSION['login_user']);
  echo "Logged out of Dashboard";
  ?&gt; 
  </code></pre>
  
  <p>and tried manually entering the page, I was redirected to login, so the code is okay. But I need to manually navigate from dashboard to work. What am I doing wrong.</p>
  
  <p>add.php</p>
  
  <pre><code>&lt;?php 
         session_start();
          if(!isset($_SESSION['login_user']))
           {
            header("Location: http://www.none.com/dashboard/login.php");
          }
      ?&gt; 
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Add Product Category&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="view.css" media="all"&gt;
      &lt;script type="text/javascript" src="view.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      function validateForm() {
          var x = document.forms["form_974780"]["productname"].value;
          if (x == null || x == "") {
              alert("Please Enter New Product Name");
              return false;
          }
      }
      &lt;/script&gt;
      &lt;/head
      &lt;body id="main_body" &gt;
      &lt;?php
      if (isset($_POST['submit']))
      {
      $productname=$_POST['productname'];
  
     //conn goes here 
      $check=$conn-&gt;query("SELECT pname FROM products WHERE pname='$productname'");
      $num_rows = mysqli_num_rows($check);
      if($num_rows&gt;0)
      {
  
      echo "&lt;font color=\"white\"&gt;";
      echo("Dealer Already exists ".$productname);
      echo"&lt;/font&gt;";
      }
      else
      {
      $result=$conn-&gt;query("INSERT INTO products(pname)VALUES('$productname')");
      if($result)
      {
      echo "&lt;font color=\"white\"&gt;";
      echo("Successfully Inserted ".$productname);
      echo"&lt;/font&gt;";
      }
      else
      {
      echo "&lt;font color=\"red\"&gt;";
      echo("Error when inserting");
      echo"&lt;/font&gt;";
      }
      }
      mysqli_close($conn);
      } 
      else
      {
  
      }
      ?&gt;
          &lt;img id="top" src="top.png" alt=""&gt;
          &lt;div id="form_container"&gt;
  
              &lt;h1&gt;&lt;a&gt;Add Product Category&lt;/a&gt;&lt;/h1&gt;
              &lt;form id="form_974780" class="appnitro"  method="post" action="?" onsubmit="return validateForm()"&gt;
                          &lt;div class="form_description"&gt;
                  &lt;h2&gt;Add Product Category&lt;/h2&gt;
                  &lt;p&gt;&lt;/p&gt;
              &lt;/div&gt;                      
                  &lt;ul &gt;
  
                          &lt;li id="li_12" &gt;
              &lt;label class="description" for="element_12"&gt;Existing Product Categories  &lt;/label&gt;
              &lt;div&gt;
              &lt;select class="element select large" id="element_12" name="element_12"&gt; 
      &lt;?php 
      //conn goes here 
      $result=$conn-&gt;query("SELECT pname FROM products");
      while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
      echo "&lt;option value='".$row['pname']."'&gt;".$row['pname']."&lt;/option&gt;";
      }
      mysqli_close($conn);
      ?&gt; 
  
              &lt;/select&gt;
              &lt;/div&gt; 
              &lt;/li&gt;       &lt;li id="li_13" &gt;
              &lt;label class="description" for="element_13"&gt;Add New Category &lt;/label&gt;
              &lt;div&gt;
                  &lt;input id="element_13" name="productname" class="element text large" type="text" maxlength="350" value=""/&gt; 
              &lt;/div&gt;&lt;p class="guidelines" id="guide_13"&gt;&lt;small&gt;Enter the new Product Category to add and Click the Submit Button. &lt;/small&gt;&lt;/p&gt; 
              &lt;/li&gt;
  
                          &lt;li class="buttons"&gt;
                      &lt;input type="hidden" name="form_id" value="974780" /&gt;
  
                      &lt;input id="saveForm" class="button_text" type="submit" name="submit" value="submit"/&gt;
              &lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/form&gt; 
  
          &lt;/div&gt;
          &lt;img id="bottom" src="bottom.png" alt=""&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>