title: Passing an AD authenticated php session variable to another page
body: <p>I have an AD authentication implemented in login.php, now if the auth is successful I wanted to pass the Users Given name to another php page say app.php.</p>
  
  <p><strong>login.php</strong> </p>
  
  <pre><code>    &lt;?php
       session_start();
      if(isset($_POST['username']) &amp;&amp; isset($_POST['password'])){
      $adServer = "ldap://ad.my_domain.com";
      $ldap = ldap_connect($adServer);
      $username = $_POST['username'];
      $password = $_POST['password'];
      $ldaprdn = 'my_server' . "\\" . $username;
      ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
      ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
          $bind = @ldap_bind($ldap, $ldaprdn, $password);
      if ($bind) {
      $filter="(sAMAccountName=$username)";
      $result = ldap_search($ldap,"dc=my_domain,dc=COM",$filter);
      ldap_sort($ldap,$result,"sn");
      $info = ldap_get_entries($ldap, $result);
      for ($i=0; $i&lt;$info["count"]; $i++)
      {
          if($info['count'] &gt; 1)
          break;
              $_SESSION['user']=$info[$i]["givenname"][0];
              #echo $_SESSION['user'];
              header("Location: app.php");        }
      @ldap_close($ldap);
      } else {
      $msg = "Invalid email address / password";
      echo $msg;
      }
  
  }else{
  ?&gt;
      &lt;form action="#" method="POST"&gt;
      &lt;label for="username"&gt;Username: &lt;/label&gt;&lt;input id="username" type="text" name="username" /&gt; 
      &lt;label for="password"&gt;Password: &lt;/label&gt;&lt;input id="password" type="password" name="password" /&gt;        
          &lt;input type="submit" name="submit" value="Submit" /&gt;
      &lt;/form&gt;
  &lt;?php } ?&gt; 
  </code></pre>
  
  <p>Here is the <strong>app.php</strong></p>
  
  <pre><code>             &lt;?php
             session_start();session_regenerate_id();
        ?&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
           &lt;title&gt;My App ::Home Page&lt;/title&gt;
  
      &lt;/head&gt;
  
      &lt;body&gt;
  
      &lt;?php
          if (!isset($_SESSION['user'])) {
          header("Location: login.php"); // If session is not set that redirect to Login Page
        }
      ?&gt;
  
      // code for app 
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>AD authentication is successful but somehow the  <b>$_SESSION['user']</b>  is not getting passed to app.php. I tried to print the value of $_SESSION['user'] in login.php which is showing the expected result. it is always getting redirected to the login.php from app.php</p>
  
  <p>What am I doing wrong ? Why is isset($_SESSION['user']) failing to get the value passed from login</p>