Example #1
0
function set_login_cookie($P, $duration = null)
{
    // error_log('set cookie');
    setcookie('pb_person_id', person_cookie_token($P->id(), $duration), is_null($duration) ? null : time() + $duration, '/', person_cookie_domain(), false);
}
Example #2
0
function person_if_signed_on($norenew = false)
{
    global $person_signed_on;
    if (!is_null($person_signed_on)) {
        return $person_signed_on;
    }
    if (array_key_exists('pb_person_id', $_COOKIE)) {
        /* User has a cookie and may be logged in. */
        $id = person_check_cookie_token($_COOKIE['pb_person_id']);
        if (!is_null($id)) {
            $P = new Person($id);
            if (!$norenew) {
                /* Valid, so renew the cookie. */
                # XXX: This turns all session cookies into one-year ones!
                $duration = person_cookie_token_duration($_COOKIE['pb_person_id']);
                setcookie('pb_person_id', person_cookie_token($id, $duration), time() + $duration, '/', person_cookie_domain());
                $person_signed_on = $P;
                /* save this here so we will renew the cookie on a later call to this function without NORENEW */
            }
            return $P;
        }
    }
    return null;
}