我有一個問題,我一直在努力解決很長時間。我看了一下PHP會話課程,我建議使用localStorage的,但無濟於事如何在應用程序內使用已驗證的用戶數據
問題:
林與angularJS和PHP後臺的工作,我有2次,一個人的login.html '和另一個'info.html',2個控制器(一個用於登錄功能,另一個用於選擇用戶的數據)。我設法進行了身份驗證階段,但對於第二步,我希望當用戶進行身份驗證時,它將被重定向到其他視圖(info.html),其中將顯示此用戶的所有信息。如何從登錄功能,存儲數據,並在第二控制器使用它(第二Web服務)
的login.php
<?php
session_start();
$data = json_decode(file_get_contents("php://input"));
$connect = mysqli_connect("localhost", "root", "", "test");
if(count($data) > 0)
{
$Email=mysqli_real_escape_string($connect, $data->Email);
$password=mysqli_real_escape_string($connect, $data->password);
$query = 'SELECT * FROM `client` WHERE (EmailClient = "'.$Email.'" AND password= "'.$password.'")';
$q = mysqli_query($connect , $query);
if(mysqli_num_rows($q) > 0)
{
$_SESSION["logged_in"] = true;
$_SESSION["naam"] = $Email;
$result['email'] =$Email;
$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;
}
?>
loginCtrl
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');
});
}
});
infoCtrl:
app.controller('infoCtrl', function($scope, $http,$state,$filter){
$scope.loadColis = function(){
$http.get("http://localhost/deb/info.php")
.success(function(data){
$scope.names = data;
});
}
info.php的
...
$query = "SELECT * FROM client where ???" ;
....
我不知道如何獲取用戶認證的數據,我該怎麼辦嗎?
在此先感謝
謝謝,我試圖做你的建議,但我在info.php文件中得到這個錯誤,說這個令牌不是定義的 – SalamSalam