Пример #1
0
 public function checkAuthentication()
 {
     $this->customer = null;
     if (isset($_COOKIE[$this->cookie_name])) {
         $arr = explode('-', $_COOKIE[$this->cookie_name]);
         $session_id = intval($arr[0]);
         $session_token = $arr[1];
     }
     if (isset($session_id)) {
         $this->session = new CustomerSession($this->db, $session_id);
         if (isset($this->session) && $this->session->is_loaded && CustomerAuthentication::verifyPassword($session_token, $this->session->val('customer_session_token_hash'))) {
             $expires = time() + CustomerAuthentication::$session_expire;
             $session = new CustomerSession($this->db);
             $session->data['customer_session_id'] = $session_id;
             $session->data['customer_session_expires'] = SqlQuery::mysqlTimestamp($expires);
             $session->save();
             setcookie($this->cookie_name, $this->session->val('customer_session_id') . '-' . $session_token, $expires, '/', false, false);
             $this->customer = new Customer($this->db, $this->session->val('customer_session_customer_id'));
             $this->updateLastAccess();
         }
     }
     if ($this->isAuth()) {
         $this->customer_id = $this->customer->val('customer_id');
     } else {
         $this->customer_id = 0;
     }
 }
Пример #2
0
<?php

require_once $home_dir . 'models/customer.m.php';
require_once $home_dir . 'models/custsess.m.php';
$sessions = CustomerSession::Select($db, 'customer_sessions', 'customer_session_expires <= ?', [SqlQuery::mysqlTimestamp(time())], 's', null, null);
foreach ($sessions as $session) {
    $customer = new Customer($db, $session->val('customer_session_customer_id'));
    $session->deleteById();
    if ($customer->val('customer_anonymous')) {
        $customer->deleteById();
    }
}
echo 'Sessions cleared.';