In PHP, I use the if to determine if the user is logged in or not, and depending on the result, displays the main menu (if registered) or the message โyou need to log inโ if not. I do it like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" href="style.css" type="text/css" /> <title>Home</title> </head> <body> <div id="header"> <a href="index.php"><img src="wtcdblogo.png" alt="WTC DB logo" /></a> </div> <?php if($_SESSION['loggedIn'] == 1) { echo "<div id='main'>MAIN MENU stuff goes here</div>"; } else { echo "<div id='main'>Please login...</div>"; } ?> </body> </html>
As you can see, the code that displays either the main menu or the message "please log in" is produced by echo . Is this a bad practice, maybe there is a better way?
By the way, I cut most of the HTML from echo in my snippet above. The main menu is made up of a list, but I was not worried that, since it is not relevant to the issue, I think.
html php echo
james246
source share