Strange thing with PHP token confirmation
one text
Solution:
The problem was solved by adding a check for the existence of $request.
if($request){//This one
    if($request->token==$_SESSION['token']){
   
  ...some code...
}else{
      echo "Token confirmation error!";
    };
  };
Source