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


Only variables should be passed by reference in session creating

我有一个会话类,我试图在其中生成会话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

我猜,问题就在这里:

$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);