简体   繁体   English

无法通过Parse \\ ParseUser识别用户,但该用户存在于$ _SESSION中

[英]User not recognized through Parse\ParseUser, but exists in $_SESSION

I'm currently writing a site built in PHP using Parse.com to store the site's data. 我目前正在使用Parse.com编写一个用PHP构建的网站,以存储该网站的数据。 I've used parse in several projects before and some of the features fit extremely well. 我之前在多个项目中使用过parse,其中一些功能非常适合。 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)
?>

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" 此代码仅与parse给出的PHP示例中的代码进行了少量修改,但无论“ Logged In”的状态如何,似乎都返回false

Session start is called to ensure the session is running, and calling print_r($_SESSION) outputs a dump which includes the relevant user object. 调用会话启动以确保会话正在运行,并调用print_r($_SESSION)输出包含相关用户对象的转储。

I understand it's likely something silly that I've missed, but any pointers in the right direction would be much appreciated. 我了解我可能错过了一些愚蠢的东西,但是任何朝着正确方向发展的指针将不胜感激。

For reference here - I was using a dedicated windows server that was configured in a somewhat non-standard way. 作为参考-我使用的是以某种非标准方式配置的专用Windows服务器。 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. 此后,我们已经从Windows服务器迁移,因为Windows-以及一系列无关的问题意味着使用CentOS更加容易。

This problem was solved by explicitly calling parse's session storage setter - ParseClient::setStorage( new ParseSessionStorage() ); 通过显式调用parse的会话存储setter- ParseClient::setStorage( new ParseSessionStorage() );解决此问题ParseClient::setStorage( new ParseSessionStorage() );

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. 这是出乎意料的,因为$_SESSION全局$_SESSION确实包含了相关信息-但在设置会话存储之前,解析不会进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM