PHP code example of haojohnny / formid

1. Go to this page and download the library: Download haojohnny/formid 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/ */

    

haojohnny / formid example snippets


protected $options = [
    'host'       => 'redis',
    'port'       => 6379,
    'password'   => '',
    'select'     => 0,
    'timeout'    => 0,
    'expire'     => 0,
    'persistent' => false,
];

protected $config = [
    'prefix' => 'form_id_',  // form-id缓存前缀
    'count'  => 50,          // form-id最大保存数量
    'expire' => '7 days'     // form-id有效期(必须是strtotime函数能识别的语义字符串,有效期必须小于等于7天)
];



use Haojohnny\Formid\FormId;

// 方法一:数据存储默认使用Redis.php的连接实例
$form = new FormId();

// 方法二:手动注入redis实例
$redis = new \Redis;
$redis->connect('127.0.0.1', 6379, 0);
$form = new FormId($redis);

// 在实例化时传入form-id配置
$options = [
    'prefix' => 'form_id_',
    'count'  => 50,
    'expire' => '7 days'
];

$redis = new \Redis;
$redis->connect('127.0.0.1', 6379, 0);

$form = new FormId($redis, $options);

$form->save('user_id:1001', 'form-value');

echo $form->get('user_id:1001'); // form-value
echo $form->get('user_id:1002'); // null