PHP Session Handling (read function) Problem
I have a class that handle SESSION in my code and store session data in DB. In Read callback function I write a query and load data from DB and return the value but when dump $_SESSION this is empty!
I trace the code and my query is corrent and data load but not set session value. this problem apear in subdomains but session_id and COOKIE is correct.
my read function code:
function read($session_id)
{
$result = @mysql_query("
SELECT
session_data
FROM
session_table
WHERE
session_id = '".$session_id."' AND
session_expire > '".time()."'
");
if (is_resource($result) && @mysql_num_rows($result) > 0) {
$fields = @mysql_fetch_assoc($result);
return $fields["session_data"];
}
return "";
}
My Log:
read function log:
SELECT
session_data
FROM
sessions_table
WHERE
session_id = '389dd7fc7bc19ffead7274c0ad860896' AND
session_expire > '1295954400'
read function result log:
Array
(
[session_data] => corret serialized data
)
write function log:
UPDATE
sessions_table
SET
session_data = '开发者_StackOverflow社区',
session_expire = '1295955840'
WHERE
session_id = '389dd7fc7bc19ffead7274c0ad860896'
Don't use the error supression operator (@). That's what prevents you from seeing the errors you made in your code. That's why you don't know where the error is in your code. That's why you have to ask where the error is in your code.
Actually, I do not see any errors in your code either, but e.g. if the database was not set up up correctly or there were an error in your SQL syntax, mysql_query would tell you that.
精彩评论