1

So i'm trying to create a parse login with php and i'm having some issues. I can login succesfull and print the session data. But when i refresh the page all the data is gone and i get redirected back to my login page. Here is the code of the two files:

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');
}

?>

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 {
       // 
    }
}

?>

Can someone please help me with this problem?

RDV

1
  • 1
    As i know that session_start() must be in the first line of each file. Commented Feb 12, 2015 at 17:34

1 Answer 1

3

I know it's a bit late but I had the same problem as you. The Parse PHP docs are not that well covered and they missed a very important part. They make you think that the storage is set by default to use the $_SESSION variable but never specify that you should setup the storage before. The answer in this question is what you where looking for:

session_start();

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

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

Hope it helps anyone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.