title: Variable PHP download-header file name?
body: <p>What's the proper syntax for this?</p>
  
  <pre><code>header('Content-Disposition: attachment; filename="{$_SESSION['name']} . '.txt');
  </code></pre>
  
  <p>This file works, though only properly when "view source" (HTML not formatted but contains correct line breaks).</p>
  
  <pre><code>&lt;?php
  header("Content-type: text/html");
  session_start();
      if(file_exists("chat") &amp;&amp; filesize("chat") &gt; 0){
          $handle = fopen("chat", "r");
          $contents = fread($handle, filesize("chat"));
          fclose($handle);
          ob_start();
  $download = strip_tags($contents, '&lt;br&gt;');
  $processed = preg_replace('#&lt;br\s*/?&gt;#i', "\n", $download);
  echo $processed;
  $var = ob_get_clean();
  echo $var;
      }
  ?&gt;
  </code></pre>
  
  <p>The <code>$_SESSION['name']</code> variable is something like <code>guest_158512</code> and if you view the source of the page I'm trying to save, it has all the line breaks. How do I save the current page as <code>guest_158512.txt</code> with the proper syntax?</p>