Make PHP generated web content available only to your users! I derived this function from some PHP code that I used on the administrative portion of my database driven sites. userLogged() returns true if the cookies named UserName and PassWord exist in the MySQL database as a pair. If not, it displays the content of $LogInPage.
The main thought behind this was to display the same login for all my admin pages, without have to repeat the same HTML code. Another purpose for this code was to keep MySQL queries, and other back-end code from being executed without permission.