So I'm using Parse.com with PHP for my user system but it doesn't work as expected. When I call the signUp() method the new user is successfully saved in Parse DB and is logged in but if I navigate to another page ParseUser::getCurrentUser() doesn't seem to fetch the current user. The same thing happens with the ParseUser::logIn() method. Here's part of my code:
<?php
require 'vendor/autoload.php';
use Parse\ParseClient;
ParseClient::initialize('*, *, *');
use Parse\ParseUser;
use Parse\ParseException;
use Parse\ParseSessionStorage;
function showForm() {
echo "
<form action='user.php' method='POST'>
Όνομα (χωρίς #)<br />
<input type='text' name='name' required><br /><br />
Κωδικός πρόσβασης<br />
<input type='password' name='password' required><br /><br />
<input type='submit' name='login' value='Σύνδεση'> <input type='submit' name='register' value='Εγγραφή'>
</form>
";
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['login'])) {
try {
$user = ParseUser::logIn($_POST['name'], $_POST['password']);
echo "<a href='add.php'>Continue</a>";
$currentUser = ParseUser::getCurrentUser();
echo $currentUser->getUsername();
} catch (ParseException $error) {
echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
showForm();
}
} else if (isset($_POST['register'])) {
$user = new ParseUser();
$user->set("username", $_POST['name']);
$user->set("password", $_POST['password']);
try {
$user->signUp();
echo "Εγγραφήκατε επιτυχώς!";
$currentUser = ParseUser::getCurrentUser();
echo $currentUser->getUsername();
} catch (ParseException $ex) {
echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
showForm();
}
}
} else {
showForm();
}
?>
<input type='text' name='name' required />. It's currently not valid HTML.catchaftercatch (ParseException $error)and see what went wrong.