PHPackages                             marsapp/system-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marsapp/system-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marsapp/system-helper
=====================

Helper for system operation.

0.2.0(4y ago)02MITPHPPHP ^7

Since Apr 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/marshung24/system-helper)[ Packagist](https://packagist.org/packages/marsapp/system-helper)[ Docs](https://github.com/marshung24/system-helper)[ RSS](/packages/marsapp-system-helper/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

System Helper
=============

[](#system-helper)

Helper for system operation.

[![Latest Stable Version](https://camo.githubusercontent.com/7d19ed2954a9a9c66291fab4dff20fe03a08c45812bbc4220f07094e57f39ab2/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f7374727563747572652f762f737461626c65)](https://packagist.org/packages/marshung/io) [![Total Downloads](https://camo.githubusercontent.com/496a9a6f201c7fcbd33b5fa8ab91b2b4cb311e901f8d49800305ccf6ddde616b/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f7374727563747572652f646f776e6c6f616473)](https://packagist.org/packages/marshung/io) [![Latest Unstable Version](https://camo.githubusercontent.com/a7f36ae2411b28a00c5477281564f5aa13b7fe919af0f5d5e3f840c17dba8669/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f7374727563747572652f762f756e737461626c65)](https://packagist.org/packages/marshung/io) [![License](https://camo.githubusercontent.com/a510a99d9f4da1b2a4598a82e33926e9a563d625d00b0fd16298583df31f759e/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f7374727563747572652f6c6963656e7365)](https://packagist.org/packages/marshung/io)

[![plastic](https://camo.githubusercontent.com/1a77ac46b55765fdb62f4a536830dbdf7423c889f9f6ecf2fb891fc69318f796/68747470733a2f2f736869656c64732e696f2f62616467652f7374796c652d706c61737469632d677265656e3f7374796c653d706c6173746963)](https://camo.githubusercontent.com/1a77ac46b55765fdb62f4a536830dbdf7423c889f9f6ecf2fb891fc69318f796/68747470733a2f2f736869656c64732e696f2f62616467652f7374796c652d706c61737469632d677265656e3f7374796c653d706c6173746963)

1. Outline
==========

[](#1-outline)

- [System Helper](#system-helper)
- [1. Outline](#1-outline)
- [2. Description](#2-description)
- [3. Installation](#3-installation)
    - [3.1. composer install](#31-composer-install)
- [4. Dependency](#4-dependency)
- [5. Usage](#5-usage)
    - [5.1. Cookie](#51-cookie)
        - [5.1.1. Setting](#511-setting)
        - [5.1.2. Cookie Default Option - Single](#512-cookie-default-option---single)
            - [5.1.2.1. Description](#5121-description)
            - [5.1.2.2. Parameters](#5122-parameters)
            - [5.1.2.3. Return Values](#5123-return-values)
            - [5.1.2.4. Example](#5124-example)
        - [5.1.3. Set Cookie Default Option - Multiple](#513-set-cookie-default-option---multiple)
            - [5.1.3.1. Description](#5131-description)
            - [5.1.3.2. Parameters](#5132-parameters)
            - [5.1.3.3. Return Values](#5133-return-values)
            - [5.1.3.4. Example](#5134-example)
        - [5.1.4. Set Cookie](#514-set-cookie)
            - [5.1.4.1. Description](#5141-description)
            - [5.1.4.2. Parameters](#5142-parameters)
            - [5.1.4.3. Return Values](#5143-return-values)
            - [5.1.4.4. Example](#5144-example)
        - [5.1.5. Set Cookie on root domain](#515-set-cookie-on-root-domain)
            - [5.1.5.1. Description](#5151-description)
        - [5.1.6. Get Cookie](#516-get-cookie)
            - [5.1.6.1. Description](#5161-description)
        - [5.1.7. Delete Cookie](#517-delete-cookie)
            - [5.1.7.1. Description](#5171-description)
        - [5.1.8. Delete Cookie on root domain](#518-delete-cookie-on-root-domain)
            - [5.1.8.1. Description](#5181-description)
- [6. Example](#6-example)
- [7. Contributing](#7-contributing)

2. [Description](#outline)
==========================

[](#2-description)

3. [Installation](#outline)
===========================

[](#3-installation)

3.1. composer install
---------------------

[](#31-composer-install)

```
$ composer require marsapp/system-helper
```

4. [Dependency](#outline)
=========================

[](#4-dependency)

- PHP7

5. [Usage](#outline)
====================

[](#5-usage)

5.1. Cookie
-----------

[](#51-cookie)

- library for Cookie operating
- Wrap the PHP native function/variable setcookie()/$\_COOKIE to enrich the function and simplify the usage method.
- Extra features:
    - Support Cookie prefix packaging
    - Support default values: expires, path, domain, secure, httponly
    - Dedicated function: Root domain access

### 5.1.1. Setting

[](#511-setting)

- 使用前設定

```
// 引入Composer autoload
include('../vendor/autoload.php');

// 宣告使用 SystemHelper
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');
```

### 5.1.2. Cookie Default Option - Single

[](#512-cookie-default-option---single)

#### 5.1.2.1. Description

[](#5121-description)

```
cookieOption(string $param, string $value = null) : string|null

```

#### 5.1.2.2. Parameters

[](#5122-parameters)

- $param : string
    - The target parameter of the cookie default options.
- $value : string
    - New data.

> - When $param does not exist, return null
> - When there is $param but no $value(null), get the current value of $param
> - When there is $param and $value, after updating the data, the updated value will be returned

#### 5.1.2.3. Return Values

[](#5123-return-values)

string|null

#### 5.1.2.4. Example

[](#5124-example)

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

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

### 5.1.3. Set Cookie Default Option - Multiple

[](#513-set-cookie-default-option---multiple)

#### 5.1.3.1. Description

[](#5131-description)

```
cookieOptions(array $options = []) : array

```

#### 5.1.3.2. Parameters

[](#5132-parameters)

- $options : array
    - batch update cookie default options.

#### 5.1.3.3. Return Values

[](#5133-return-values)

array, return complete cookie default options.

#### 5.1.3.4. Example

[](#5134-example)

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

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

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

### 5.1.4. Set Cookie

[](#514-set-cookie)

#### 5.1.4.1. Description

[](#5141-description)

```
cookieSet(string $name, string $value = "", array $options = []) : bool

```

> Set Cookie, Wrap the PHP native function setcookie() to simplify usage.

#### 5.1.4.2. Parameters

[](#5142-parameters)

- $name : string
    - The name of the cookie.
- $value : string
    - The value of the cookie.
- $options : array
    - 'prefix' =&gt; '', // Cookie前綴，預設無前綴
    - 'expires' =&gt; time()+3600, // 過期時間，預設無期限
    - 'path' =&gt; '/', // 存放路徑
    - 'domain' =&gt; "", // 所屬網域
    - 'secure' =&gt; true, // 是否只在https生效
    - 'httponly' =&gt; false, // 是否只能通過HTTP協議訪問

#### 5.1.4.3. Return Values

[](#5143-return-values)

bool, like PHP function setcookie()

#### 5.1.4.4. Example

[](#5144-example)

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

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

> - $options可用參數
>     - 'prefix' =&gt; '', // Cookie前綴，預設無前綴
>     - 'expires' =&gt; time()+3600, // 過期時間，預設無期限
>     - 'path' =&gt; '/', // 存放路徑
>     - 'domain' =&gt; "", // 所屬網域
>     - 'secure' =&gt; true, // 是否只在https生效
>     - 'httponly' =&gt; false, // 是否只能通過HTTP協議訪問

### 5.1.5. Set Cookie on root domain

[](#515-set-cookie-on-root-domain)

#### 5.1.5.1. Description

[](#5151-description)

```
cookieSetRoot(string $name, string $value = "", array $options = []) : bool

```

> Like `cookieSet()`, but domain fixed on root domain.

### 5.1.6. Get Cookie

[](#516-get-cookie)

#### 5.1.6.1. Description

[](#5161-description)

```
cookieGet(string $name) : mixed

```

> 取得目標Cookie值

### 5.1.7. Delete Cookie

[](#517-delete-cookie)

#### 5.1.7.1. Description

[](#5171-description)

```
cookieExpired(string $name, array $options = []) : bool

```

> Delete target cookie.

### 5.1.8. Delete Cookie on root domain

[](#518-delete-cookie-on-root-domain)

#### 5.1.8.1. Description

[](#5181-description)

```
cookieExpiredRoot(string $name, array $options = []) : bool

```

> Like `cookieExpired()`, but domain fixed on root domain.

6. [Example](#outline)
======================

[](#6-example)

see: example/example-cookie.php

7. [Contributing](#outline)
===========================

[](#7-contributing)

- 20210424: MarsHung Build repo &amp; development
- 20210621: MarsHung Add function cookieOption(), cookieOptions(), COOKIE\_DEFAULT\_PREFIX

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~33 days

Total

4

Last Release

1747d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34496839?v=4)[MarsHung](/maintainers/marshung24)[@marshung24](https://github.com/marshung24)

---

Top Contributors

[![marshung24](https://avatars.githubusercontent.com/u/34496839?v=4)](https://github.com/marshung24 "marshung24 (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marsapp-system-helper/health.svg)

```
[![Health](https://phpackages.com/badges/marsapp-system-helper/health.svg)](https://phpackages.com/packages/marsapp-system-helper)
```

###  Alternatives

[xj/yii2-bootbox-widget

yii2-bootbox-widget

11106.3k1](/packages/xj-yii2-bootbox-widget)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
