Hi,
Based on the code you pasted from dl-file.php it appears to be working as intended – displaying one message if you’re logged in and another if you’re not.
If what you’re trying to achieve is to restrict access to your files for people who are not logged in, please see this blog post which explains how to do that: https://aftabablog.wordpress.com/2017/02/17/how-to-make-your-uploads-in-wordpress-visible-only-for-logged-in-users/
Hope this helps!
-Bjørnar