You can do this with a conditional statement. See this guide for more information.
Conditional Statements
As a note, I used to do this but now show members online to everyone. I thought it was better to show the site was active, guests expect to see who is online from other forum software.