title: How to change CSS with PHP and create a cookie in the same place
body: <p>So, I have a bit of code and it basically checks to see if a <code>cookie</code> is created and if it is, then set an <code>element</code> to <code>display: none;</code> and if it isn't, then set an <code>element</code> to <code>display: block;</code> and create a <code>cookie</code> (this way, as long as the <code>cookie</code> remains, the display will only change that first time).</p>
  
  <p>Unfortunately, I ran into a dilemma and I think I know why. I know <code>cookie</code>s have to be called <em>before</em> all other things relating to HTML. But any CSS has to change in the <code>head</code> or the <code>body</code> (in this case, the <code>body</code>). So, I am wondering how I can get this done and if it isn't possible/isn't a good idea, what a better solution might be.</p>
  
  <p>Also, I thought about having it check if the <code>cookie</code> has been created before and do the whole <code>cookie</code>-creating part and then later on have the it check to see if the <code>cookie</code> exists and if it doesn't, change the <code>element</code> to <code>display: block;</code>, but this wouldn't work because it would create a cookie the first time it went to the page before it even changed the CSS.</p>
  
  <p>Code:</p>
  
  <pre><code>if(isset($_COOKIE["beenToCyanCoding"])) {
      echo '
          &lt;style type="text/css"&gt;
              #welcomeToCyanCoding {
                  display: none;
              }
          &lt;/style&gt;';
  }
  else {
      echo '
          &lt;style type="text/css"&gt;
              #welcomeToCyanCoding {
                  display: block;
              }
          &lt;/style&gt;';
      setcookie("beenToCyanCoding", date("m/d/y"), time() + 10 * 365 * 24 * 60 * 60, "/");
  }
  </code></pre>