Is this a bug in PHP or just strange behavior?
<p>I have 2 scripts/pages, both using session data.</p>

<p>Page 1 is a table with some data, one of the pieces of data is an email address. This page is only accessible if <code>$_SESSION['email'] == 'myEmail@email.com'</code>. There is a button on page 1 in each row of the table that sends an AJAX call to script/page 2 which emails that corresponding email address.</p>

<p>In page 2 there is another check for <code>$_SESSION['email'] == 'myEmail@email.com'</code>. </p>

<p>Then it sets <code>$email = $_POST['email']</code> and calls a mail() function. After this script executes it automatically changes <code>$_SESSION['email']</code> to be equal to <code>$email</code>.</p>

<p>I've changed the variable name from <code>$email</code> to <code>$sendToEmail</code> and this fixes the issue.</p>

<p>My question is why does it do this? Is this a bug or a feature?</p>

<p><strong>EDIT:</strong></p>

<p>This is the mail.php code in it's entirety.</p>

<pre><code>&lt;?php
session_start();
define("_VALID_PHP", true);
require_once('init.php');

if ($_SESSION['email'] == 'email@gmail.com') {
    if (isset($_POST['iid'])) {
        $iid = $_POST['iid'];
        if (isset($_POST['email'])) {
            $sendToEmail = $_POST['email'];
            $query = $db-&gt;query("SELECT id FROM esns WHERE iid='$iid' AND status=0");
            if (mysql_num_rows($query) &gt; 0) {
                $data['success'] = false;
                $data['msg'] = "Email cannot be sent until all ENS's are checked for this invoice.";
            }
            else {
                $query = $db-&gt;query("SELECT uid, md5 FROM invoice WHERE id='$iid'");
                $row = $db-&gt;fetch($query);
                $uid = $row['uid'];
                $md5 = $row['md5'];
                $query = $db-&gt;query("SELECT email FROM users WHERE id='$uid'");
                $row = $db-&gt;fetch($query);
                if ($row['email'] == $email) {
                    $clean = array();
                    $bad = array();
                    $invalid = array();
                    $query = $db-&gt;query("SELECT esn, status, carrier FROM esns WHERE iid='$iid'");

                    $headers = "From: email@site.com";
                    $subject = "New Message from site.com";

                    $body = "Hello";

                    $mail = mail($sendToEmail,$subject,$body,$headers);

                    if (!$mail) {
                        $data['success'] = false;
                        $data['msg'] = "There was an error sending the email."; 
                    }
                    else {
                        $query = mysql_query("UPDATE invoice SET paid=2 WHERE id='$iid'");
                        $data['success'] = true;
                    }
                }
                else {
                    $data['success'] = false;
                    $data['msg'] = "There was an mismatch with the emails. The posted email does not belong to this invoice.";  
                }
            }
        }
        else {
            $data['success'] = false;
            $data['msg'] = "Post data not sent/recieved correctly: `email` is no set.";
        }
    }
    else {
        $data['success'] = false;
        $data['msg'] = "Post data not sent/recieved correctly: `iid` is no set.";
    }
}
else {
    $data['success'] = false;
    $data['msg'] = "Your are not logged in as an administrator.";
}
echo json_encode($data);
?&gt;
</code></pre>
