title: Automatic resizing header seems to rely on a PHP Echo. I don't want the echo to display anything though.
body: <p>I have some code that works out your screen resolution and then resizing a header based on the results. </p>
  
  <p>If it's 1600x900 we don't want to resize, we want to keep the header as 1500x500. 
  Otherwise, we set the header to 100% each. </p>
  
  <p>However. 
  At 1600x900 the header will resize, code doesn't work, UNLESS I echo a previous piece of code that displays the users screen resolution on screen. I don't actually want to display that echo though. </p>
  
  <p>If I go in and echo, then delete the echo, it'll work, but I need it to work first time. So i'm wondering if there's some way to echo without actually printing or an equivalent idea. </p>
  
  <p>Relevant header code:</p>
  
  <pre><code>&lt;!-- This is start of header code --&gt;
  &lt;!-- All you need to do is put in the new header image and change site title like before --&gt;
  &lt;?php
      session_start();
      if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height']))
      {
          &lt;!-- put a echo here for debugging --&gt;
          'User resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];
      }
      else if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) 
      {
          $_SESSION['screen_width'] = $_REQUEST['width'];
          $_SESSION['screen_height'] = $_REQUEST['height'];
          header('Location: ' . $_SERVER['PHP_SELF']);
      } 
      else
      {
         &lt;!-- put a echo here for debugging --&gt;
         '&lt;script type="text/javascript"&gt;window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&amp;height="+screen.height;&lt;/script&gt;';
      }
  ?&gt;
  
  &lt;!-- Note, putting those echos above will fix my site so that on 1600x900 it won't be 100% anymore. THEN removing echo will have the site the way I want it but this isn't ideal. I need it to work first time since other non-programmers will be working with this code --&gt;
  
  &lt;?php if ($_SESSION['screen_width'] == 1600 &amp;&amp; $_SESSION['screen_height'] == 900)
  {
       //Don't change style, this is a resolution we want precise width on
      $width1 = "1500"."px";
      $height1 = "500"."px";
      //echo $width1;
      //echo $height1;
      //echo "Header won't change";
  }
  else
  {
        //Change style, any other resolution we go for 100%
      $width1 = "100"."%";
      $height1 = "100"."%";
      //echo $width1;
      //echo $height1;
      //echo "Header will change";
  }
  
  $text = "&lt;img src='https://i.imgur.com/AdK7a7u.png' style='width:$width1;height:$height1&gt;&lt;/center&gt;";
  
  preg_match_all("/&lt;img.*&gt;/",$text,$out);
  foreach($out as $t1)
  {
      foreach($t1 as $img)
      {
          preg_match("/.*height:(.*?);width:(.*?);.*/",$img,$out2);
          $height = $out2[1];
          $width = $out2[2];
          $text = str_replace($out2[0],str_replace("&lt;img","&lt;img width='" . $width1 . "' height='" . $height1 . "'",$out2[0]),$text);
      }
  }
  echo $text;
  ?&gt;
  </code></pre>
  
  <p>Images of the code running on a site:</p>
  
  <p><a href="https://i.stack.imgur.com/rVvKw.png" rel="nofollow noreferrer">Expected output for 1600x900</a></p>
  
  <p><a href="https://i.stack.imgur.com/7y9eJ.png" rel="nofollow noreferrer">Actual output</a></p>
  
  <p><a href="https://i.stack.imgur.com/xrCbK.png" rel="nofollow noreferrer">What the echo looks like</a></p>