用户无法通过 Parse\ParseUser 识别,但存在于 $_SESSION 中 [英] User not recognized through Parse\ParseUser, but exists in $_SESSION

查看:32
本文介绍了用户无法通过 Parse\ParseUser 识别,但存在于 $_SESSION 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个用 PHP 构建的网站,使用 Parse.com 来存储该网站的数据.我之前在几个项目中使用过 parse,其中一些功能非常适合.我现在遇到了无法正确检测到登录用户的问题.

I'm currently writing a site built in PHP using Parse.com to store the site's data. I've used parse in several projects before and some of the features fit extremely well. I've now run into an issue where a logged in user can't be detected properly.

<?php
  use Parse\ParseClient;
  use Parse\ParseObject;
  use Parse\ParseQuery;
  use Parse\ParseGeoPoint;
  use Parse\ParseUser;


  ParseClient::initialize('Omitted', 'Omitted', 'Omitted');
  (... truncated)

  function get_user(){
    //BROKEN.
    //TODO: Fix
    $currentUser = ParseUser::getCurrentUser();
    if ($currentUser) {
        return $currentUser->getObjectId();
    } else {
        return false;
    }
  }

  (... truncated)
?>

此代码仅与 parse 给出的 PHP 示例中的代码略有修改,但无论登录"状态如何,似乎都返回 false

This code is only marginally modified from that in the PHP examples given by parse, but seems to return false no matter what the state of "Logged In"

Session start 被调用以确保会话正在运行,并且调用 print_r($_SESSION) 输出一个包含相关用户对象的转储.

Session start is called to ensure the session is running, and calling print_r($_SESSION) outputs a dump which includes the relevant user object.

我知道这可能是我错过的一些愚蠢的事情,但任何指向正确方向的指针都将不胜感激.

I understand it's likely something silly that I've missed, but any pointers in the right direction would be much appreciated.

推荐答案

此处仅供参考 - 我使用的是专用 Windows 服务器,该服务器以某种非标准方式进行配置.我们已经从 Windows 服务器迁移,因为 Windows - 还有一连串不相关的问题意味着使用 CentOS 更容易.

For reference here - I was using a dedicated windows server that was configured in a somewhat non-standard way. We've since migrated from the windows server, because Windows - and also a barrage of unrelated issues meant it was just easier to use CentOS instead.

通过显式调用 parse 的 session storage setter 解决了这个问题 - ParseClient::setStorage( new ParseSessionStorage() );

This problem was solved by explicitly calling parse's session storage setter - ParseClient::setStorage( new ParseSessionStorage() );

这是出乎意料的,因为 $_SESSION 全局确实包含相关信息 - 但 parse 在设置会话存储之前不会选择它.

This was unexpected as the $_SESSION global did contain the relevant info - but parse wouldn't pick this up until the session storage was set.

这篇关于用户无法通过 Parse\ParseUser 识别,但存在于 $_SESSION 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆