PHP repeating piece of code wtih access to variables
<p>How to repeat the same PHP snippet in different PHP files?
For example I define the variable <code>$user</code>, then I insert PHP code, which have an access to this variable. 
<strong>Update:</strong>
I'm going to use this with if statement</p>

<blockquote>
  <p>Example(without if statement):</p>
</blockquote>

<pre><code>    function sanitizeString($var)
    {
    $var = htmlentities($var, ENT_QUOTES, "UTF-8");
    return mysql_real_escape_string($var);
    }
    $user = sanitizeString($_POST['user']);
    $pass = sanitizeString($_POST['pass']);
    //code i want to repeat in different files
    $user=$user;
    $pass=$pass;
    #salt generation
    $salt=uniqid(mt_rand(), true);
    #Add data to tables
    queryMysql("INSERT INTO accounts VALUES('$user', '".hash('sha512',$pass+$salt)."', '$salt', '$cookie_value')");
    mysql_query("INSERT INTO passwordreset VALUES('$user', NULL, NULL)");
    //end of code to repeat
</code></pre>
