Reputation: 6139
I am working on a small eCommerce site which is using a simple user log-in system.
I am testing by setting the id in the database as a $_SESSION var so I can keep track of some other stuff.
There was an odd problem where PHP was not setting the proper values to variables IF the $_SESSION var was set before I did a comparison, and I would love to know why.
This IF statement shows the session var commented out, but this is where it was placed initially. In this placement, the IF returned false (even if i cast the var as INT) and the token value only returned the first digit.
$stmt = $db->prepare("select id, token, confirmed from customers where email = ?");
$stmt->execute(array($email));
$customerId = $stmt->fetchAll();
$customerId = $customerId[0];
if (!empty($customerId))
{
//$_SESSION['customerId'] = $customerId['id'];
if ($customerId['confirmed'] == 0)
{
$sendConfirm = 1;
$uuid = $customerId['token'];
echo $sendConfirm."/".$customerId['token'];
}
}
I know this sounds crazy, but if I moved the session var under the IF or removed it, everything works as expected. This is PHP 5.4.
Can anyone think of a reason why this would happen?
Upvotes: 2
Views: 146
Reputation: 922
I believe the issue is the session variable has the same name as a local variable.
This has happened to me before and I feel your pain.
Upvotes: 1