title: PHP user defined function not being called?
body: <p>I have a webpage and I have a session_check file that is used to check the session variables. I added <code>require 'session_check.php'</code> at the top of the webpages where it is required. I have also used <code>echo</code> to check that the <code>session_check.php</code> file got called. </p>
  
  <p>I have a function in session_check.php that gets called when it's time to log out, but it never gets called. Could you please help me out? Thanks :)</p>
  
  <p><em>Code for <code>session_check.php</code></em>:</p>
  
  <pre><code>&lt;?php
      //Database Connection 
      $db_host = $_SERVER['DB_HOST'];
      $db_uname = $_SERVER['DB_UNAME'];
      $db_pwd = $_SERVER['DB_PWD'];
      $db_name = $_SERVER['DB_DB'];
  
      $db_link = mysql_connect($db_host,$db_uname,$db_pwd);
      if(!$db_link){
          die("Could Not Connect:".mysql_error($db_link));
      }
      mysql_select_db($db_name, $db_link) or die('Can\'t use db:'. mysql_error($db_link));
  
      //Logout function
      function user_logout($uname){
          $query = "UPDATE user SET last_used_token='' WHERE username='$uname'";
          mysql_close($db_link);
          session_destroy();
          header('Location:index.php');
          exit(); 
      }
  
      //Getting session variables
      session_start();
      session_regenerate_id();
      $cur_authkey = $_SESSION['authkey'];
      $uname = $_SESSION['username'];
  
      //Session data checking 
  
      $query = "SELECT last_used_token FROM user WHERE username='$uname'";
      $result = mysql_query($query, $db_link) or die('Error while updating auth key &lt;br /&gt; Query:'.$query.'MySQL error no:'.mysql_errno().'&lt;br /&gt; MySQL error:'.mysql_error($db_link));
      $row = mysql_fetch_assoc($result);
  
      if($cur_authkey != $row['last_used_token']){
          user_logout($uname);
      }   
  
  ?&gt;
  </code></pre>
  
  <p><em>Partial Code of the calling webpage</em></p>
  
  <pre><code>&lt;?php
      require 'session_check.php';
      mysql_close($db_link);
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;.....&lt;/html&gt;
  </code></pre>