I am trying to make a simple login PHP API and calling it from Axios via VueJS.
On login attempt I send axios POST request to desired script on the same domain like so:
axios.post("/api/open/auth/login", {
data: {
username: this.name,
password: this.pass
}
})
Then in PHP I check inserted data from POST and if it's correct, I set session variables like so (there is session_start() at the beggining of the file):
$_SESSION["userID"] = $row->id_users;
$_SESSION["username"] = $row->name;
this works fine so far and I am certain that this part of code runs alright and session variables should be set, but I created another script, that is supposed to check, wheter the user is logged in by checking those session variables like so:
if ( isset($_SESSION["userID"]) && isset($_SESSION["username"]) )
{
jsonResponseOk("Session is set.");
}
else
{
jsonResponseError("Session is not set.");
}
Here is what I can't wrap my head around, although the session variables should be set, when I logged in before, this always falls to ELSE.