本文介绍了新的parse.com php API-currentUser不回馈用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用用户凭据登录

I am able to login with user credentials with

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

但是如果我以后尝试获取currentUser

but if I try to get the currentUser afterwards with

$currentUser = ParseUser::getCurrentUser();
if ($currentUser) {
    // do stuff with the user
} else {
    // show the signup or login page
}

未设置$ currentUser.

$currentUser is not set.

我怀疑这更多是我不知道的php问题".只要不注销,就可以在代码中保留currentUser的任何提示,我都很感激.

I suspect this more to be a php "issue" that I don't know. I am greatful for any hint for keeping currentUser retained in my code as long I do not log out.

推荐答案

为了使getCurrentUser()方法起作用,必须定义要使用的会话存储的类型.您可以使用ParseSessionStorage类来实现此目的:

In order for the getCurrentUser() method to work, you must define the type of session storage to use. You can use the ParseSessionStorage class to achieve this:

use Parse\ParseClient;
use Parse\ParseUser;
use Parse\ParseSessionStorage;

session_start();

// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'yyy', 'zzz');

// set session storage
ParseClient::setStorage( new ParseSessionStorage() );

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

$currentUser = ParseUser::getCurrentUser();

print_r( $currentUser );

这篇关于新的parse.com php API-currentUser不回馈用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:47