PHP code example of homevip / session
1. Go to this page and download the library: Download homevip/session library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
homevip / session example snippets
namespace App\Http\Controllers\Auths;
use App\Http\Controllers\Controller;
use homevip\Session;
class V1Controller extends Controller
{
/**
* session 快捷操作
* 2020_05_07
*
* @param string $name
* @param string $value
* @param integer $options
* @return void
*/
public function session(string $name, $value = '', int $options = 7200)
{
// session 初始化
$Session = Session::instance()
->lifetime($options)
->domain('.hy9z.com')
->httponly(false)
->redisConnect(env('REDIS_HOST'), env('REDIS_PORT'), env('REDIS_PASSWORD'), env('REDIS_DB'));
if ('' === $value) {
// 获取 session
return $Session->get($name);
} elseif (is_null($value)) {
// 删除缓存
return $Session->del($name);
} else {
// 缓存 session
return $Session->set($name, $value);
}
}
}
$key = 'aaaa';
$Session = new \App\Http\Controllers\Auths\V1Controller();
if (!$Session->session($key)) {
dump('空');
$Session->session($key, date('H:i:s'));
}
var_dump($Session->session($key));