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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器