解析PHP会话未存储

时间:2015-02-12 17:16:06

标签: php session parse-platform

所以我试图用php创建一个解析登录,我有一些问题。我可以登录succesfull并打印会话数据。但是当我刷新页面时,所有数据都消失了,我被重定向回我的登录页面。以下是两个文件的代码:

的index.php

<?php

require 'autoload.php';

session_start();
use Parse\ParseClient;
use Parse\ParseUser;

ParseClient::initialize('myapi',    
                        'myapi', 
                        'myapi');

print_r($_SESSION);
$currentUser = ParseUser::getCurrentUser();


if ($currentUser) {

} else {
   header('Location: login.php');
}

&GT;

的login.php

<?php

require 'autoload.php';
session_start();
use Parse\ParseClient;
use Parse\ParseUser;
use Parse\ParseException;



ParseClient::initialize('myapi',    
                        'myapi', 
                        'myapi');


$currentUser = ParseUser::getCurrentUser();
 print_r($_SESSION);
if($_SERVER['REQUEST_METHOD'] == 'POST') 
{ 
    if(isset($_POST['user'], $_POST['pass'])) 
    {     
        $username = trim($_POST['user']); 
        $password = trim($_POST['pass']); 

        try {
        $user = ParseUser::logIn($username, $password);
        header('Location: index.php');
        } catch (ParseException $error) {

        }
    } 
} else {

    if ($currentUser) {
        header('Location: index.php');
    } else {
       // 
    }
}

&GT;

有人可以帮我解决这个问题吗?

RDV

1 个答案:

答案 0 :(得分:3)

我知道它有点晚了,但我遇到了和你一样的问题。解析PHP文档并没有得到很好的覆盖,它们错过了一个非常重要的部分。它们会让您认为存储设置默认设置为使用$ _SESSION变量,但从未指定您之前应设置存储。 this question中的答案就是你在寻找的地方:

session_start();

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

// [!] Set session storage
ParseClient::setStorage( new ParseSessionStorage() );

希望它可以帮助任何人。