PHPackages                             webiik/session - 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. webiik/session

ActiveLibrary

webiik/session
==============

The Session provides safe way to work with sessions.

1.0(7y ago)0894MITPHPPHP &gt;=7.2

Since Feb 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/webiik/session)[ Packagist](https://packagist.org/packages/webiik/session)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-session/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (4)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)

Session
=======

[](#session)

The Session provides safe way to work with sessions.

Installation
------------

[](#installation)

```
composer require webiik/session
```

Example
-------

[](#example)

```
$session = new \Webiik\Session\Session();
$session->setToSession('foo', 'bar');
if ($session->isInSession('foo')) {
    echo 'Session foo has value: ' . $session->getFromSession('foo');
}
$session->delFromSession('foo');
```

> **NOTICE:** If you can, don't forget to call [session\_write\_close()](https://github.com/webiik/webiik) before time intensive operations. Otherwise users of your app can experience serious lags.

Configuration
-------------

[](#configuration)

### setDomain

[](#setdomain)

```
setDomain(string $domain): void
```

**setDomain()** sets the (sub)domain that the session cookie is available to.

```
$session->setDomain('mydomain.tld');
```

### setUri

[](#seturi)

```
setUri(string $uri): void
```

**setUri()** sets the path on the server in which the session cookie will be available on.

```
$session->setUri('/');
```

### setSecure

[](#setsecure)

```
setSecure(bool $bool): void
```

**setSecure()** indicates that the session cookie should only be transmitted over a secure HTTPS connection from the client. The default value is **FALSE**.

```
$session->setSecure(true);
```

### setHttpOnly

[](#sethttponly)

```
setHttpOnly(bool $bool): void
```

**setHttpOnly()** indicates that the session cookie should only be accessible through the HTTP protocol. The default value is **FALSE**.

```
$session->setHttpOnly(true);
```

### setSessionName

[](#setsessionname)

```
setSessionName(string $name): void
```

**setSessionName()** sets the name of the session which is used as cookie name. The default value is **PHPSESSID**.

```
$session->setSessionName('mySessionName');
```

### setSessionDir

[](#setsessiondir)

```
setSessionDir(string $path): void
```

**setSessionDir()** defines the argument which is passed to the save handler. If you choose the default files handler, this is the path where the files are created.

```
$session->setSessionDir(__DIR__ . '/tmp');
```

### setSessionGcProbability

[](#setsessiongcprobability)

```
setSessionGcProbability(int $sessionGcProbability): void
```

**setSessionGcProbability()** in conjunction with `setSessionGcDivisor()` is used to manage probability that the gc (garbage collection) routine is started. The default value is 1.

```
$session->setSessionGcProbability(1);
```

### setSessionGcDivisor

[](#setsessiongcdivisor)

```
setSessionGcDivisor(int $sessionGcDivisor): void
```

**setSessionGcDivisor()** coupled with `setSessionGcProbability()` defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using GsProbability/GcDivisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. The default value of GcDivisor is 100.

```
$session->setSessionGcDivisor(100);
```

### setSessionGcLifetime

[](#setsessiongclifetime)

```
setSessionGcLifetime(int $sec): void
```

**setSessionGcLifetime()** specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on `setSessionGcProbability()` and `setSessionGcDivisor()`).

```
$session->setSessionGcLifetime(1440);
```

> **Note:** If different scripts have different values of gcLifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with `setSessionDir()`.

Adding
------

[](#adding)

### setToSession

[](#settosession)

```
setToSession(string $key, $value): void
```

**setToSession()** sets **$value** to the session under given **$key**.

```
$session->setToSession('foo', 'bar');
```

### addToSession

[](#addtosession)

```
addToSession(string $key, $value): void
```

**addToSession()** ads **$value** to the session under given **$key**.

```
$session->addToSession('foo', 'bar');
```

### sessionStart

[](#sessionstart)

```
sessionStart(): bool
```

**sessionStart()** starts the session. Use it when you need to work directly with **$\_SESSION** global.

```
$session->sessionStart();
```

### sessionRegenerateId

[](#sessionregenerateid)

```
sessionRegenerateId(): void
```

**sessionRegenerateId()** replaces the current session id with a new one, and keeps the current session information. Also the original session is kept.

```
$session->sessionRegenerateId();
```

Check
-----

[](#check)

### isInSession

[](#isinsession)

```
isInSession(string $key): bool
```

**isInSession()** determines if **$key** is set in session and if its value is not **NULL**.

```
$session->isInSession('foo');
```

Getting
-------

[](#getting)

### getFromSession

[](#getfromsession)

```
getFromSession(string $key)
```

**getFromSession()** gets value from the session by **$key**.

```
$session->getFromSession('foo');
```

### getAllFromSession

[](#getallfromsession)

```
getAllFromSession()
```

**getAllFromSession()** returns all values stored in the session.

```
$session->getAllFromSession();
```

Deletion
--------

[](#deletion)

### delFromSession

[](#delfromsession)

```
delFromSession(string $key): void
```

**delFromSession()** removes value from the session by **$key**.

```
$session->delFromSession('foo');
```

### dellAllFromSession

[](#dellallfromsession)

```
dellAllFromSession(): void
```

**dellAllFromSession()** removes all values from the session.

```
$session->dellAllFromSession();
```

### sessionDestroy

[](#sessiondestroy)

```
sessionDestroy(): bool
```

**sessionDestroy()** removes all values from the session and un-sets the session.

```
$session->sessionDestroy();
```

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

2632d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (261 commits)")

---

Tags

session

### Embed Badge

![Health badge](/badges/webiik-session/health.svg)

```
[![Health](https://phpackages.com/badges/webiik-session/health.svg)](https://phpackages.com/packages/webiik-session)
```

###  Alternatives

[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48619.2M541](/packages/nette-http)[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[laminas/laminas-session

Object-oriented interface to PHP sessions and storage

8122.7M113](/packages/laminas-laminas-session)[aura/session

Provides session management functionality, including lazy session starting, session segments, next-request-only ("flash") values, and CSRF tools.

2041.2M69](/packages/aura-session)[mezzio/mezzio-session

Session container and middleware for PSR-7 applications

24982.3k16](/packages/mezzio-mezzio-session)

PHPackages © 2026

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