如何检查用户是否使用knockout登录

Is there any way to know if the user is logged in using knockout js? How can I get the user's data? I tried this code,

var userId = '<%=HttpContext.Current.Session["user_session"] %>';
    alert(userId);

I put it in a view model. But it is not working.

Here is the requested PHP code,

public function login($email,$pass)
{
   try
   {
      $stmt = $this->db->prepare("SELECT * FROM accounts WHERE emailadd=:email LIMIT 1");
      $stmt->execute(array(':email'=>$email));
      $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
      if($stmt->rowCount() > 0)
      {
         if(password_verify($pass, $userRow['password']))
         {
            $_SESSION['user_session'] = $userRow['id'];
            return true;
         }
         else
         {
            return false;
         }
      }
   }
   catch(PDOException $e)
   {
       echo $e->getMessage();
   }
   }

And here is the js code,

function homeViewModel(params) {
    var self = this;
    var userId = '<%=HttpContext.Current.Session["user_session"] %>';
    alert(userId);
    return self;
}
查看全部
duandi4238
duandi4238
2016/08/16 16:45
  • php
  • knockout.js
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复