dongmaxi6763 2015-11-12 09:36
浏览 26

如何使用PHP管理Angular.js应用程序中的会话

I have one doubt regarding using of session data in Angular.js Application.Suppose after login user has to get into to the dashboard page.When user logged in it save the following data in session.

$selquery = "SELECT * FROM db_user WHERE login_name='".$user_name."' and password='".$password."'";
$selres = mysql_query($selquery); 
if(mysql_num_rows($selres ) > 0){
    $result=mysql_fetch_array($selres); 
    $_SESSION["admin_id"]=$result['user_id'];
    $_SESSION["admin_user_name"]=$result['first_name']." ".$result['last_name'];
    $_SESSION["admin_user_type"]=$result['user_type'];
    $_SESSION["admin_email_id"]=$result['email_id'];
    $_SESSION["admin_role_id"]=$result['role_id'];
    $_SESSION["admin_clg_id"]=$result['colg_id'];
    $_SESSION["admin_dept_id"]=$result['dept_id'];
    //$result['msg'] = 'Login successfull...';
}else{
    header("HTTP/1.0 401 Unauthorized");
    $result['msg'] = 'Invalid username or password, Please try again...';
}

I need when user will enter into dashboard page it will check first the session data if present then the dashboard page will display otherwise it will again redirect to login page. I am explaining my controller file below.

dashboardController.js:

var dashboard=angular.module('Channabasavashwara');
dashboard.controller('adminController',function($scope,$http,$state,$window){
    //$scope.submenu=false;     

     //$state.go('dashboard',{}, { reload: true });

     $scope.no_of_college=0;
     $scope.no_of_stream=0;
     $scope.no_of_department=0;
     $scope.no_of_course=0;
     $scope.no_of_users=0;

     //alert("aaaa");

     $http({
         method: 'GET',
         url: 'php/college/getAdminSummery.php',
         headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
     }).then(function successCallback(response){
         $scope.no_of_college = response.data['no_college'];
         $scope.no_of_stream = response.data['no_stream'];
         $scope.no_of_department = response.data['no_department'];
         $scope.no_of_course = response.data['no_course'];
         $scope.no_of_users = response.data['no_user'];
         //alert("::"+$scope.no_of_college);
     },function errorCallback(response) {
        $state.go('/',{}, { reload: true }); 
     });



     $http({
         method: 'GET',
         url: 'php/Login/session.php',
         headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
     }).then(function successCallback(response){
         //console.log('session',response);
         $scope.userType=response.data[0].first_name+" "+response.data[0].last_name;
     },function errorCallback(response) {
        $state.go('/',{}, { reload: true }); 
     });
     $scope.logout=function(){
         $http({
         method: 'POST',
         url: 'php/Login/logout.php',
         headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
     }).then(function successCallback(response){
         //console.log('session',response);
         //alert(response);
     },function errorCallback(response) {
         //console.log('session',response);
         //alert(response);
     });
     }

})

Here also i need to set the time to destroy the session automatically. Please help me to resolve this issue.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用