[英]updating a session id in a MySQL db - PHP
The following function is supposed to take in a PHP
session_id
and update it, otherwise the user will be logged out in 5 min: 以下函数应该接收一个
PHP
session_id
并对其进行更新,否则用户将在5分钟内注销:
function update_session_id( $session_id = "" )
{
$stmt = "UPDATE session SET start=NOW() WHERE id='$session_id';";
$query = mysql_query( $stmt )
or die( mysql_error() );
if( $query )
{
return true;
}
return false;
}
For some reason, PHP
is returning me "\\"p9bb7t9gmchtvr6scr8hseufm6\\""
even though I'm using stripslashes()
, which does not seems to remove those slashes at all. 由于某些原因,即使我使用的是
stripslashes()
, PHP
也会向我返回"\\"p9bb7t9gmchtvr6scr8hseufm6\\""
,这似乎根本没有删除那些斜杠。 That's why my query is not working ... The code where that function is called it's pretty simple: 这就是为什么我的查询无法正常工作的原因。调用该函数的代码非常简单:
else if( strcmp( $action, "query" ) == 0 )
{
$session_id = stripslashes( $_POST['session_id'] );
$data = getCustomer();
update_session_id( $session_id );
echo json_encode( $session_id );
}
but I don't know why I'm getting those extra slashes on my string. 但是我不知道为什么我的琴弦上会出现那些多余的斜线。 Any thoughts?
有什么想法吗? Update A query example:
更新查询示例:
"UPDATE session SET start=NOW() WHERE id='\"p9bb7t9gmchtvr6scr8hseufm6\"';"
The correct code to generate the statement is: 生成该语句的正确代码是:
$stmt = sprintf("UPDATE session SET start=NOW() WHERE id='%s'",
mysql_real_escape_string($session_id)
);
If you see double quotes in the resulting query, that means the double quotes were already there . 如果在结果查询中看到双引号,则意味着双引号已经存在 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.