Php 使用会话
我的应用程序通过服务器使用信息。我有一行代码在运行时连接到我的数据库,称为“stream”。它的主要功能是从名为photos的数据库表中检索用户设备令牌Php 使用会话,php,Php,我的应用程序通过服务器使用信息。我有一行代码在运行时连接到我的数据库,称为“stream”。它的主要功能是从名为photos的数据库表中检索用户设备令牌 $result = query("INSERT INTO login(username, pass, device_token) VALUES('%s','%s','%s')", $user, $pass, $token); 这对我的应用程序来说是非常有价值的信息。有人能帮我将上面语句中的$token值存储到会话中,以便在这个方法中使用它吗
$result = query("INSERT INTO login(username, pass, device_token) VALUES('%s','%s','%s')", $user, $pass, $token);
这对我的应用程序来说是非常有价值的信息。有人能帮我将上面语句中的$token值存储到会话中,以便在这个方法中使用它吗
function handleMessage()
{
$userId = $this->getUserId();
/*$text = $this->getString('text', self::MAX_MESSAGE_LENGTH, true);*/
// First, we get the record for the sender of the message from the
// active_users table. That gives us the nickname, device token, and
// secret code for that user.
$stmt = $this->pdo->prepare('SELECT * FROM active_users WHERE user_Id = ? LIMIT 1');
$stmt->execute(array($userId));
$user = $stmt->fetch(PDO::FETCH_OBJ);
if ($user !== false)
{
// Put the sender's name and the message text into the JSON payload
// for the push notification.
$payload = $this->makePayload($user->nickname/*, $text*/);
// Find the device tokens for all other users who are registered
// for this secret code. We exclude the device token of the sender
// of the message, so he will not get a push notification. We also
// exclude users who have not submitted a valid device token yet.
$stmt = $this->pdo->prepare("SELECT device_token FROM active_users WHERE secret_code = ? AND device_token <> ? AND device_token <> '0'");
$stmt->execute(array($user->secret_code, $user->device_token));
$tokens = $stmt->fetchAll(PDO::FETCH_COLUMN);
// Send out a push notification to each of these devices.
foreach ($tokens as $token)
{
$this->addPushNotification($token, $payload);
}
}
}
我知道这听起来很复杂,但我相信这是可以做到的 $\u会话['token']=$token;,有什么问题吗?例如,我最终如何在第二种方法中实现它?具体地说,请注意指定$token和$tokens变量的现有foreach语句的位置。我不明白您想做什么。你的问题提到了一个名为photos的表,但在你发布的任何代码中都没有提到这一点。你在循环所有令牌。哪一个进入会议?都是吗?您可以只执行$\u会话['tokens']=$tokens;。这个问题很不清楚,但会话的总体思路很简单:只需将您想要的任何内容分配给$_SESSION['variablename',,然后您就可以在其他页面中使用它。只需确保所有页面都以session_start;开头即可;。$\u会话['token']=$token;,有什么问题吗?例如,我最终如何在第二种方法中实现它?具体地说,请注意指定$token和$tokens变量的现有foreach语句的位置。我不明白您想做什么。你的问题提到了一个名为photos的表,但在你发布的任何代码中都没有提到这一点。你在循环所有令牌。哪一个进入会议?都是吗?您可以只执行$\u会话['tokens']=$tokens;。这个问题很不清楚,但会话的总体思路很简单:只需将您想要的任何内容分配给$_SESSION['variablename',,然后您就可以在其他页面中使用它。只需确保所有页面都以session_start;开头即可;。