New parse.com php API - currentUser not giving back a user(新的 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.
}
但是如果我之后尝试使用
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 ParseParseClient;
use ParseParseUser;
use ParseParseSessionStorage;
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 不回馈用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:新的 parse.com php API - currentUser 不回馈用户


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01