PHP/PDO select data from database with session variable
I have got the following issue, which I can't seem to solve. I'm using PDO with MySQL in the following function:
public function checkST($database) {
if (isset($_SESSION['user'])) {
$ticket = $_SESSION['user']['session_ticket'];
$check = $database->query("SELECT * FROM users WHERE session_ticket = 'ST-627eed61b0dcc8fe04068e23c9e9ace10fd59cf7-8104' LIMIT 1");
$result = $check->fetchColumn();
var_dump($result);
if ($result != 1) {
header('Location: ../?p=login');
}
} else {
header('Location: ../?p=login');
}
}
$ticket = $_SESSION['user']['session_ticket'];
$check = $database->query("SELECT * FROM users WHERE session_ticket = '".$ticket."' LIMIT 1");
$result = $check->fetchColumn();开发者_JAVA百科
var_dump($result);
returns:
bool(false)
But when I insert my session ticket like:
$ticket = $_SESSION['user']['session_ticket'];
$check = $database->query("SELECT * FROM users WHERE session_ticket = 'ST-627eed61b0dcc8fe04068e23c9e9ace10fd59cf7-8104' LIMIT 1");
$result = $check->fetchColumn();
var_dump($result);
it returns:
string(1) "1"
which is the expected result.
It is not so clear.. however try this:
$check = $database->query('SELECT * FROM users WHERE session_ticket = '.$ticket.' LIMIT 1');
精彩评论