title: How to run code once per user session in PHP?
body: <p>Okay, Ive searched around and found how this is supposed to be done. For example, finding <a href="https://stackoverflow.com/questions/6709449/run-php-function-once">this question</a>. However it is not working for me, so I must be doing something wrong, but darned if I know what.</p>
  
  <p>Okay... here is my little code block: </p>
  
  <pre><code>&lt;?php
      session_start();
  
      if(!isset($_SESSION['didit'])) {
          $url = "http://www.mysite.com/clients/vatera.asmx/DoSomething";
          file_get_contents($url);
          $_SESSION['didit'] = true; 
      }
  ?&gt;
  </code></pre>
  
  <p>The <strong>url</strong> <code>file_get_contents</code> is all working perfectly. The only thing not working is the "run once" check. It is running the <strong>url</strong> code EVERY time through the page. It should only run it the first time you hit the page in a session. This block is located immediately following the <code>&lt;html&gt;</code> tag in my page. </p>
  
  <p>Some other things I have tried: </p>
  
  <pre><code>if(empty($_SESSION['didit']))
  if($_SESSION['didit'] != true)
  if($_SESSION['didit'] &lt;&gt; true)
  </code></pre>
  
  <p>I also tried moving the line setting the variable to precede the <strong>$url</strong> assignment.</p>
  
  <p>None of these have worked. It continues to run the code EVERY time the page is loaded.
  Thanks in advance!</p>