I am getting Undefined array key “userid” error but user id field exist in database I am trying to get userid by following is my function where I am trying to get user id
function checkAuthStatusAndReturnUserID($writeDB) {
if(!isset($_SERVER['HTTP_AUTHORIZATION']) || strlen($_SERVER['HTTP_AUTHORIZATION']) < 1) {
$message = null;
if(!isset($_SERVER['HTTP_AUTHORIZATION'])) {
$message = "Access token is missing from the header";
} else {
if(strlen($_SERVER['HTTP_AUTHORIZATION']) < 1) {
$message = "Access token cannot be blank";
}
}
sendResponse(401, false, $message);
}
// get supplied access token from authorisation header - used for delete (log out) and patch (refresh)
$accesstoken = $_SERVER['HTTP_AUTHORIZATION'];
try {
// create db query to check access token is equal to the one provided
$query = $writeDB->prepare('select adminsession.userid as usrid, accesstokenexpiry from adminsession, admin where adminsession.userid = admin.id and accesstoken = :accesstoken');
$query->bindParam(':accesstoken', $accesstoken, PDO::PARAM_STR);
$query->execute();
$rowCount = $query->rowCount();
if($rowCount === 0) {
// send json error response using function for unsuccessful log out response
sendResponse(401, false, "Invalid access token $accesstoken");
}
$row = $query->fetch(PDO::FETCH_ASSOC);
$returned_userid = $row['userid'];
$returned_accesstokenexpiry = $row['accesstokenexpiry'];
you can see in the above image userid column exists
