Sailthru_Client::setHorizonCookie PHP Method

setHorizonCookie() public method

Set Horizon cookie
public setHorizonCookie ( string $email, string $domain = null, integer $duration = null, boolean $secure = false ) : boolean
$email string horizon user email
$domain string
$duration integer
$secure boolean
return boolean
    public function setHorizonCookie($email, $domain = null, $duration = null, $secure = false)
    {
        $data = $this->getUserByKey($email, 'email', ['keys' => 1]);
        if (!isset($data['keys']['cookie'])) {
            return false;
        }
        if (!$domain) {
            $domain_parts = explode('.', $_SERVER['HTTP_HOST']);
            $domain = $domain_parts[sizeof($domain_parts) - 2] . '.' . $domain_parts[sizeof($domain_parts) - 1];
        }
        if ($duration === null) {
            $expire = time() + 31556926;
        } else {
            if ($duration) {
                $expire = time() + $duration;
            } else {
                $expire = 0;
            }
        }
        return setcookie('sailthru_hid', $data['keys']['cookie'], $expire, '/', $domain, $secure);
    }