在会话创建中,只能通过引用传递变量

时间:2016-04-02 18:19:18

标签: php session

我有一个会话类,其中我试图生成会话ID并将其存储到数据库中,但它给出的错误是“只应通过引用传递变量”

这是脚本部分 - >

private function newSid() {

        $this->sessionId=$this->generateString($this->sid_len);

        while ( $this->getSidCount($this->sessionId) > 0 || is_int($this->sessionId) ) {

                $this->sessionId=$this->generateString($this->sid_len);

        }

        $this->forcedExpire = time()+ $this->session_max_duration;
        $expireTime = time() + $this->session_duration;

        $this->SQLStatement_InsertSession->bindParam(':expires', $expireTime, PDO::PARAM_INT);
        $this->SQLStatement_InsertSession->bindParam(':forcedExpires', $this->forcedExpire, PDO::PARAM_INT);
        $this->SQLStatement_InsertSession->bindParam(':sid', $this->sessionId, PDO::PARAM_STR, $this->sid_len);
        $this->SQLStatement_InsertSession->bindParam(':ua', $this->getUa(), PDO::PARAM_STR, 40);

        return $this->SQLStatement_InsertSession->execute();

}

了解详细信息,请访问完整会话课程https://www.twekr.com/session.txt

1 个答案:

答案 0 :(得分:1)

我的猜测,问题在于:

$this->SQLStatement_InsertSession->bindParam(':ua', $this->getUa(), PDO::PARAM_STR, 40);

而不是尝试将$this->getUa()分配给变量:

$ua = $this->getUa();
$this->SQLStatement_InsertSession->bindParam(':ua', $ua, PDO::PARAM_STR, 40);