title: Outputting HTML with echo considered bad practice in PHP?
body: <p>In PHP, I'm using an <code>if</code> statement to identify whether a user is logged in or not, and depending on the result, displaying the main menu (if logged in) or a "you need to login" message if not. I am doing this like so:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;
      &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
      &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="header"&gt;
         &lt;a href="index.php"&gt;&lt;img src="wtcdblogo.png" alt="WTC DB logo" /&gt;&lt;/a&gt;
      &lt;/div&gt;
      &lt;?php 
         if($_SESSION['loggedIn'] == 1) {
            echo "&lt;div id='main'&gt;MAIN MENU stuff goes here&lt;/div&gt;";
         } else {
            echo "&lt;div id='main'&gt;Please login...&lt;/div&gt;";
         } 
      ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As you can see, the code to display either the main menu or the "please login" message is produced by an <code>echo</code>. Is this bad practice, perhaps there's a better way? </p>
  
  <p>By the way, I've cut out most of the HTML from the <code>echo</code>s in my snippet above. The main menu is made up of a list, but I didn't bother including that as it's irrelevant to the question, I guess.</p>