6

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 is not set.

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.

2
  • 1
    I've never used the parse library, but looks like a session issue... Did you check if session is started by the library or is it you that must start it? Commented Aug 17, 2014 at 7:42
  • Oh, who can read... "By default, whenever you use any signup or login methods, the user will be saved in PHP Session storage (The $_SESSION superglobal.)". Now I only have to know the name of the session... THANKS FOR YOU QUICK REPLY. Commented Aug 17, 2014 at 7:51

1 Answer 1

16

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 Parse\ParseClient;
use Parse\ParseUser;
use Parse\ParseSessionStorage;

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 );
Sign up to request clarification or add additional context in comments.

1 Comment

GREAT! That is what I was missing. Thank you. I now have to see how I can access (perform queries) from user restricted classes, since now I am able to read only from classes which have no user restrictions and get results. I use ACL in my iOS App and I try to figure out how to set defaultACL in php to access them. In Javascript this was very easy, in php I don't know yet. But again, GREAT THANKS!

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.