title: What is the difference between client-side and server-side programming?
body: <p>I have this code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var foo = 'bar';
      &lt;?php
          file_put_contents('foo.txt', ' + foo + ');
      ?&gt;
  
      var baz = &lt;?php echo 42; ?&gt;;
      alert(baz);
  &lt;/script&gt;
  </code></pre>
  
  <p>Why does this not write "bar" into my text file, but alerts "42"?</p>
  
  <hr>
  
  <p>NB: Earlier revisions of this question were explicitly about PHP on the server and JavaScript on the client. The essential nature of the problem and solutions is the same for <em>any</em> pair of languages when one is running on the client and the other on the server (even if they are the same language). Please take this in to account when you see answers talking about specific languages.</p>