コード例 #1
0
 public function actionCookie()
 {
     //        Yii::$app->response->format = Response::FORMAT_RAW;
     //        $headers = Yii::$app->response->headers;
     //        $headers->add('Content-type', 'image/gif');
     //        $headers->add('Content-Length', '42');
     //        $headers->add('Cache-Control', 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate');
     //        $headers->add('Expires', 'Wed, 11 Jan 2000 12:59:00 GMT');
     //        $headers->add('Last-Modified', 'Wed, 11 Jan 2006 12:59:00 GMT');
     //        $headers->add('Pragma', 'no-cache');
     //        echo sprintf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 255, 0, 192, 192, 192, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59);
     $clientCookie = new ClientCookie();
     if ($clientCookie->cookie_id === null) {
         $cookie = new Cookie();
         $cookie->last_activity = $cookie->create_time = date('Y-m-d H:i:s');
         $cookie->save();
         $clientCookie->cookie_id = $cookie->id;
     } else {
         $cookie = Cookie::findOne(['id' => $clientCookie->cookie_id]);
         if ($cookie !== null) {
             $cookie->last_activity = date('Y-m-d H:i:s');
             $cookie->save();
         }
     }
     //        $clientCookie->updateCategory(3, [
     //            'value' => 1
     //        ]);
     $clientCookie->save();
     echo "<pre>";
     VarDumper::dump($clientCookie);
     echo "</pre>";
 }
コード例 #2
0
ファイル: init.php プロジェクト: sydorenkovd/test-items
<?php

//namespace app\core;
use app\models\Cookie;
use app\models\Config;
use app\models\Session;
use app\models\User;
use app\classes\DB;
session_start();
$GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']];
spl_autoload_register(function ($class) {
    require_once 'classes/' . $class . '.php';
});
require_once "functions/sanitize.php";
if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
    $hash = Cookie::get(Config::get('remember/cookie_name'));
    $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]);
    if ($hashCheck->count()) {
        $user = new User($hashCheck->first()->user_id);
        $user->login();
    }
}
コード例 #3
0
 public function actionIndex()
 {
     $cookies = Cookie::find()->all();
     return $this->render('index', ['cookies' => $cookies]);
 }
コード例 #4
0
ファイル: index.php プロジェクト: piotrmus/Targematic
<?php

use app\models\Cookie;
?>
<div class="admin-default-index">
    <div class="row">
        <div class="col-md-12">
            <h1>Dashboard</h1>
        </div>
        <div class="col-md-6">
            No Cookies: <?php 
echo count($cookies);
?>
<br>
            No 7 days Active Cookies: <?php 
echo Cookie::find()->where('last_activity >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY')->count();
?>
<br>
        </div>
        <div class="col-md-6">
            Lorem ipsum
        </div>
    </div>
</div>
コード例 #5
0
ファイル: User.php プロジェクト: sydorenkovd/test-items
 public function logout()
 {
     $this->_db->delete('users_session', ['user_id', '=', $this->data()->id]);
     Session::delete($this->_sessionName);
     Cookie::delete($this->_cookieName);
 }
コード例 #6
0
ファイル: CookieEmail.php プロジェクト: piotrmus/Targematic
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCookie()
 {
     return $this->hasOne(Cookie::className(), ['id' => 'cookie_id']);
 }