title: How to use session with angularJS
body: <p>I'm working with AngularJS and PHP backend, and I'm trying to display data of authenticated user, and I have <strong>2 views</strong>, one '<strong>login.html</strong>' and the other <strong>'info.html</strong>', <strong>2 controllers</strong> (one for the login function and the other for selecting the user's data) . I implement the authentication phase but for the second step I want that when the user authenticates, it will be redirected to other view (info.html) where all the information of this user will be displayed.</p>
  
  <p><strong>I tried to</strong> use session,but it doesn't work and I don't know why.
  How can I store user's data from login function and use it in the second controller(second web service)</p>
  
  <p><strong>login.php</strong></p>
  
  <pre><code>     &lt;?php  
      session_start();
      $data = json_decode(file_get_contents("php://input"));
  
       $connect = mysqli_connect("localhost", "root", "", "user");  
  
       if(count($data) &gt; 0)  
  
       { 
  
      $Email=mysqli_real_escape_string($connect, $data-&gt;Email);
      $mdp=mysqli_real_escape_string($connect, $data-&gt;mdp);
  
      $query = 'SELECT * FROM `client` WHERE (EmailClient = "'.$Email.'" AND   mdp= "'.$mdp.'")';
  
      $q = mysqli_query($connect , $query);
  
      if(mysqli_num_rows($q) &gt; 0 )
        { 
             $token = md5($Email.time()."51395+81519851");
             $query = "UPDATE client SET token = '".$token."' WHERE EmailClient = '".$Email."'";
             mysqli_query($connect , $query);
             $_SESSION["logged_in"] = true; 
             $_SESSION["token"] = $token; 
  ; 
             $result['message'] ='Logged In';
             $result['email'] =$Email;
             $result['token'] = $token;
  
             $resultstring=json_encode($result);
             $resultstring=str_replace("null", '""', $resultstring);
             echo $resultstring;
             exit;
  
        }
       $result['code'] = 603;
             $result['message'] ='The username or password are incorrect!';
  
  
  
      $resultstring = json_encode($result);
      $resultstring = str_replace("null",'""',$resultstring);
      echo $resultstring;
      exit;
      }
  
      ?&gt;
  </code></pre>
  
  <p><strong>info.php</strong></p>
  
  <pre><code>&lt;?php  
  session_start();
   $connect = mysqli_connect("localhost", "root", "", "user");  
  
   $output = array();  
   $query = "SELECT FirstName,FamilyName,EmailClient FROM client WHERE token = '".$_SESSION['token']."'";
   $result = mysqli_query($connect, $query);  
   if(mysqli_num_rows($result) &gt; 0)  
   {  
        while($row = mysqli_fetch_array($result))  
        {  
             $output[] = $row;  
        }  
        echo json_encode($output);  
   }  
  
   ?&gt; 
  </code></pre>
  
  <p><strong>loginCtrl</strong></p>
  
  <pre><code>app.controller('loginCtrl', function($scope, $location,$state,$http,$window){
  
      $scope.submit = function()
      {
          data = {
              'Email' : $scope.Email,
              'password' : $scope.password
      };
  
          $http.post('http://localhost/deb/login.php', data)
          .success(function(data, status, headers, config,result)
          {
              console.log(data);
              $state.go('info');
  
               }
          })
          .error(function(data, status, headers, config, result)
          {      
              console.log('error');   
          });
      }
  
  });
  </code></pre>
  
  <p><strong>infoCtrl :</strong></p>
  
  <pre><code>app.controller('infoCtrl', function($scope, $http,$state,$filter){
  
      $scope.loadColis = function(){ 
                $http.get("http://localhost/deb/info.php")  
             .success(function(data){  
                  $scope.names = data;  
             });
        } 
  </code></pre>
  
  <p>I don't know how get user authenticated data, how can I do please?</p>
  
  <p>Thanks in advance</p>