title: PHP - Session inaccessible on other pages
body: <p>I have a website samplewebsite.com, and the log in function and session are working fine.</p>
  
  <p>Now I am creating a new page involving the session started at the log-in page, which is located at samplewebsite.com/sample.php. The file only contains the following code for now.</p>
  
  <pre><code>session_start();
  if(isset($_SESSION)){
  print_r($_SESSION);
  }
  </code></pre>
  
  <p>This outputs an empty array. When I check Chrome's developer tools, the Cookies tab include a PHPSESSID which I presume means that a session has actually been started.</p>
  
  <p>I am terribly frustrated why at my samplewebsite.com I am logged in and the session is picked up properly while at samplewebsite.com/sample.php I can't get the session I need at all. </p>
  
  <p>Is there some kind of error in the server's session configuration? What could have gone wrong or what are the possible causes of this problem?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is a snippet of my login file. </p>
  
  <pre><code>include "db.php";
  if (!isset($_SESSION)){session_start(); }   
  
  if (isset($_SESSION['admin'])){header("Location: /"); }
  
  if(isset($_POST['submit'])){
  
      $query = mysql_query("Select * from users where `username`='".mysql_real_escape_string($_POST['username'])."' and `password`='".md5(mysql_real_escape_string($_POST['password']))."'");
  
      if(mysql_num_rows($query) &gt; 0 ){
  
          $row = mysql_fetch_assoc($query);
  
          $_SESSION['admin'] = $row['ID'];
  
          header("Location: /"); exit();
  
  
      }
      else{
  
          echo "&lt;script&gt;alert('Account Invalid')&lt;/script&gt;";
  
      }
  
  
  }
  </code></pre>
  
  <p>The session has been init because if not I would be redirected to the login page(because of the redirect function on index.php where if $_SESSION['admin'] is not set, redirect to login). This is tested by manually deleting the session on chrome's dev tool and refreshing the page will take me the login page.</p>
  
  <p>So I am logged in and I see my session working on samplewebsite.com , but on my other tab at samplewebsite.com/sample.php, I can't echo out $_SESSION['admin'] when I try</p>
  
  <pre><code>echo $_SESSION['admin'];
  </code></pre>