目前,我的会话存储空间如下:
我的用户ID和级别显示在同一行。怎么会这样?我在我的Angular loginService中创建了vars,如下所示:
'use strict';
app.factory('loginService',function($http, $location, sessionService){
return{
login:function(data,scope){
var $promise=$http.post('data/user.php',data); //send data to user.php
$promise.then(function(msg){
var uid=msg.data;
var pass=msg.data;
var level=msg.data;
if(uid){
//scope.msgtxt='Correct information';
sessionService.set('uid',uid);
//sessionService.set('lvl',level);
$location.path('/home');
}
if(level){
sessionService.set('level',level);
$location.path('/home');
}
else {
window.alert("Wrong credentials entered");
scope.msgtxt='incorrect information';
$location.path('/login');
}
});
},
然后在我的登录脚本中,它很简单 - 它检查我的行并根据输入的用户密码和用户名返回level的值。
$user=json_decode(file_get_contents('php://input'));
if(isset($user))
{
session_start();
$useridname = $user->uid;
$userpass = md5($user->pass);
$_SESSION['uid']=$user->uid;
//get level
$sql = "SELECT lvl FROM dbo.users WHERE userid = '".$useridname."'
AND psw = ?";
$params = array($userpass);
$stmt = sqlsrv_query($conn,$sql,$params);
//if query does not work, return false
if($stmt === false){
die( print_r( sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if($row)
{
do{
//echo "You are being logged in... please wait!";
//$_SESSION['lvl']=$user->level;
print $_SESSION['level'] = $row['lvl'];
print $_SESSION['uid'];
由于一些奇怪的原因,我不能为我的生活找出如何让他们在自己的线上单独打印。没有打印,它不会在sessionStorage键和值字段中打印。无法解决这个问题,现在已经有几个小时了。
来自Angular社区的任何想法?
已编辑(data.php):
$_SESSION['uid']=$user->uid;
$_SESSION['level']=$user->level;
//get userid and level from users table according to username and password entered
$sql = "SELECT lvl FROM dbo.users WHERE userid = '".$useridname."' AND psw = ?";
已编辑(services.js):
login:function(data,scope){
var $promise=$http.post('data/user.php',data); //send data to user.php
$promise.then(function(msg,lvl){
var uid=msg.data;
var pass=pass.data;
var level=lvl.data;
if(uid){
//scope.msgtxt='Correct information';
sessionService.set('uid',uid);
sessionService.set('level',level);
$location.path('/home');
}