PHP code example of marsapp / system-helper

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

    

marsapp / system-helper example snippets


// 引入Composer autoload
er
use marsapp\helper\system\SystemHelper;

// 常數設定 - 需設 Cookie前綴、過期時間、預設路徑、根網域
define('COOKIE_DEFAULT_PREFIX', 'dev_');
define('COOKIE_DEFAULT_EXPIRES', 0);
define('COOKIE_DEFAULT_PATH', '/');
define('COOKIE_ROOT_DOMAIN', 'dev.local');

// 取得Cookie預設參數值
$httponly = SystemHelper::cookieOption('httponly');

// 設定Cookie預設參數-單筆
$httponly = SystemHelper::cookieOption('httponly', false);

// 變數設定
$options = [
    // 存放路徑
    'path' => '/tmp/',
    // 是否只能通過HTTP協議訪問
    'httponly' => false,
];

// 回傳完整Cookie預設參數
$cookieOptions = SystemHelper::cookieOptions();

// 設定Cookie預設參數-多筆
$cookieOptions = SystemHelper::cookieOptions($options);

// 變數設定
$name = 'testCookie';
$value = "test-" . mt_rand(1111, 9999);
$options = [
    // 存放路徑
    'path' => '/',
    // 是否只能通過HTTP協議訪問
    'httponly' => true,
];

// 設定Cookie
SystemHelper::cookieSet($name, $value, $options);