Logout user programmatically without redirect I need to logout the current user in my code.
For now I use : user_logout(); but this function seems to have a redirect at the end.

How can I logout a user without any redirect ?

It need to be for a single case, not a hook to every logout.

Thanks.
The logout controller (UserController::logout()) does this in a separate step.

  public function logout() {
    user_logout();
    return $this-&gt;redirect('&lt;front&gt;');
  }


You can alter the controller class for the user.logout route to replace this with custom code. 

What do you want to do instead? Building an anonymous response a redirect seems to be the most straightforward solution.