Custom PHP function - users cannot log out

I'm using custom function on my site. Some part of that php code makes the issue - when user is logged in it cannot be log out.

Please check chat transcript.
Thank you