doubi4617 2016-08-11 05:39
浏览 17
已采纳

使用javascript sdk解析平台用户登录但不能通过PHP SDK获取哪个用户登录

I am facing such a wired issue. i used JavaScript SDK to login in PARSE platform and successfully login. On the next page i am trying to get current user login using PHP SDK.

But strange no result coming, return NULL

What could be the issue ?

JavaScript:

Parse.User.logIn("myname", "mypass", {
  success: function(user) {
    // Do stuff after successful login.
  },
  error: function(user, error) {
    // The login failed. Check error to see why.
  }
});

PHP:

$currentUser = ParseUser::getCurrentUser();

Null Result here.

  • 写回答

1条回答 默认 最新

  • doupai1876 2016-08-11 07:40
    关注

    If you are login with Javascript you can access the current user using the following command:

    Parse.User.current()
    

    I don't thing that you can access the same user from PHP because you didn't login via the PHP SDK.

    You have 2 options:

    1. Login the user via the PHP SDK using the following code (from parse php docs). This is the recommended approach since you are doing it on the server.

        try {
          $user = ParseUser::logIn("myname", "mypass");
          // Do stuff after successful login.
        } catch (ParseException $error) {
          // The login failed. Check error to see why.
        }

    and then you will be able to access the current user like this:

    $currentUser = ParseUser::getCurrentUser(); 
    
    1. Login with JavaScript SDK and access to user with Parse.User.current()

    My POV

    if your is already work with PHP what i think you should do is to use Parse PHP SDK on the PHP side and trigger the PHP functions from Javascript using ajax requests. There are some workaround solution that will allow you to have the current user on both sides (PHP and JavaScript) but then you will need to deal the current user session token and this can make your app a bit complicated.

    So if you want to get the current user from PHP to JavaScript you can execute a ajax call to PHP and from PHP you can return the current user object or you can just do everything on the PHP side which is also fine.

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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