Skip to content

Phalcon Session

Updated View as Markdown

Session\Adapter\AbstractAdapter

AbstractSource on GitHub

Uses Phalcon\Storage\Adapter\AdapterInterface · Phalcon\Traits\Support\Helper\Arr\GetTrait · SessionHandlerInterface · SessionUpdateTimestampHandlerInterface

Method Summary

Properties

protectedAdapterInterface$adapter

Methods

Public · 8

close()

public function close(): bool;

Close

destroy()

public function destroy( mixed $id ): bool;

Destroy

gc()

public function gc( int $max_lifetime ): int|false;

Garbage Collector

open()

public function open(
    mixed $path,
    mixed $name
): bool;

Open

read()

public function read( mixed $id ): string;

Read

updateTimestamp()

public function updateTimestamp(
    mixed $id,
    mixed $data
): bool;

Refresh the session lifetime without changing the session data

validateId()

public function validateId( mixed $id ): bool;

Validate the session id (used when strict mode is enabled)

write()

public function write(
    mixed $id,
    mixed $data
): bool;

Write

Session\Adapter\Exceptions\AdapterRuntimeError

ClassSource on GitHub

Uses Phalcon\Session\Exception

Session\Adapter\Exceptions\InvalidSavePath

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Adapter\Exceptions\SavePathUnavailable

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $path );

Session\Adapter\Libmemcached

ClassSource on GitHub

Phalcon\Session\Adapter\Libmemcached

Uses Phalcon\Storage\AdapterFactory

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    AdapterFactory $factory,
    array $options = []
);

Libmemcached constructor.

] ], ‘defaultSerializer’ => ‘Php’, ‘lifetime’ => 3600, ‘serializer’ => null, ‘prefix’ => ‘sess-memc-’, ‘stripPrefix’ => false ]

Session\Adapter\Noop

ClassSource on GitHub

Phalcon\Session\Adapter\Noop

This is an “empty” or null adapter. It can be used for testing or any other purpose that no session needs to be invoked

<?php

use Phalcon\Session\Manager;
use Phalcon\Session\Adapter\Noop;

$session = new Manager();
$session->setAdapter(new Noop());

Uses SessionHandlerInterface · SessionUpdateTimestampHandlerInterface

Method Summary

Methods

Public · 8

close()

public function close(): bool;

Close

destroy()

public function destroy( mixed $id ): bool;

Destroy

gc()

public function gc( int $max_lifetime ): int|false;

Garbage Collector

open()

public function open(
    mixed $path,
    mixed $name
): bool;

Open

read()

public function read( mixed $id ): string;

Read

updateTimestamp()

public function updateTimestamp(
    mixed $id,
    mixed $data
): bool;

Refresh the session lifetime without changing the session data

validateId()

public function validateId( mixed $id ): bool;

Validate the session id (used when strict mode is enabled)

write()

public function write(
    mixed $id,
    mixed $data
): bool;

Write

Session\Adapter\Redis

ClassSource on GitHub

Phalcon\Session\Adapter\Redis

Uses Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Storage\AdapterFactory

Method Summary

Properties

protectedbool$lockAcquired = false
protectedint$lockExpiry = 30Lock time-to-live in seconds. The lock is not refreshed during the request: a request that runs longer than this expiry loses its lock silently and a concurrent request may then acquire it (the token-guarded release still avoids deleting the newer lock). Raise this above the longest expected request to retain the lock for the whole request.
protectedstring$lockKey = ""
protectedint$lockRetries = 100
protectedstring$lockToken = ""
protectedint$lockWaitTime = 50000
protectedbool$lockingEnabled = false
protectedstring$prefix = ""

Methods

Public · 4

__construct()

public function __construct(
    AdapterFactory $factory,
    array $options = []
);

Constructor

close()

public function close(): bool;

Close - releases the session lock if one is held

destroy()

public function destroy( mixed $id ): bool;

Destroy

read()

public function read( mixed $id ): string;

Read

Protected · 2

acquireLock()

protected function acquireLock( mixed $id ): bool;

Tries to acquire the session lock, pausing lockWaitTime microseconds between attempts, up to lockRetries times

releaseLock()

protected function releaseLock(): void;

Releases the session lock - only when this instance still owns it

Session\Adapter\Stream

ClassSource on GitHub

Phalcon\Session\Adapter\Stream

This is the file based adapter. It stores sessions in a file based system

<?php

use Phalcon\Session\Manager;
use Phalcon\Session\Adapter\Stream;

$session = new Manager();
$files = new Stream(
    [
        'savePath' => '/tmp',
    ]
);
$session->setAdapter($files);

@property array $options @property string $prefix @property string $path

Uses Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Session\Adapter\Exceptions\InvalidSavePath · Phalcon\Session\Adapter\Exceptions\SavePathUnavailable · Phalcon\Traits\Php\FileTrait · Phalcon\Traits\Php\IniTrait · Phalcon\Traits\Support\Helper\Arr\GetTrait · Phalcon\Traits\Support\Helper\Str\DirSeparatorTrait

Method Summary

Properties

protectedarray$options = []Session options
protectedstring$prefix = ""Session prefix

Methods

Public · 8

__construct()

public function __construct( array $options = [] );

Constructor

destroy()

public function destroy( mixed $id ): bool;

gc()

public function gc( int $max_lifetime ): int|false;

Garbage Collector

open()

public function open(
    mixed $path,
    mixed $name
): bool;

Ignore the savePath and use local defined path

read()

public function read( mixed $id ): string;

Reads data from the adapter

updateTimestamp()

public function updateTimestamp(
    mixed $id,
    mixed $data
): bool;

Refresh the session file modification time without changing its data

validateId()

public function validateId( mixed $id ): bool;

Validate the session id (used when strict mode is enabled)

write()

public function write(
    mixed $id,
    mixed $data
): bool;
Protected · 2

getGlobFiles()

protected function getGlobFiles( string $pattern ): array|false;

Gets the glob array or returns false on failure

getPrefixedName()

protected function getPrefixedName( mixed $name ): string;

Helper method to get the name prefixed

Session\Bag

ClassSource on GitHub

Phalcon\Session\Bag

This component helps to separate session data into “namespaces”. Working by this way you can easily create groups of session variables into the application

$user = new \Phalcon\Session\Bag("user");

$user->name = "Kimbra Johnson";
$user->age  = 22;

@property DiInterface|null $container @property string $name @property ManagerInterface $session;

Uses Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Di\InjectionAwareInterface · Phalcon\Session\ManagerInterface · Phalcon\Support\Collection

Method Summary

Methods

Public · 7

__construct()

public function __construct(
    ManagerInterface $session,
    string $name
);

clear()

public function clear(): void;

Destroys the session bag

getDI()

public function getDI(): DiInterface;

Returns the DependencyInjector container

init()

public function init( array $data = [] ): void;

Initialize internal array

remove()

public function remove( string $element ): void;

Removes a property from the internal bag

set()

public function set(
    string $element,
    mixed $value
): void;

Sets a value in the session bag

setDI()

public function setDI( DiInterface $container ): void;

Sets the DependencyInjector container

Session\BagInterface

InterfaceSource on GitHub

Phalcon\Session\BagInterface

Interface for Phalcon\Session\Bag

  • Phalcon\Session\BagInterface

Method Summary

Methods

Public · 10

__get()

public function __get( string $element ): mixed;

__isset()

public function __isset( string $element ): bool;

__set()

public function __set(
    string $element,
    mixed $value
): void;

__unset()

public function __unset( string $element ): void;

clear()

public function clear(): void;

get()

public function get(
    string $element,
    mixed $defaultValue = null,
    string $cast = null
): mixed;

has()

public function has( string $element ): bool;

init()

public function init( array $data = [] ): void;

remove()

public function remove( string $element ): void;

set()

public function set(
    string $element,
    mixed $value
): void;

Session\Exception

ClassSource on GitHub

Phalcon\Session\Exception

Exceptions thrown in Phalcon\Session will use this class

Session\Exceptions\InvalidSessionAdapter

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\InvalidSessionId

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\InvalidSessionName

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\SessionAlreadyStarted

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\SessionModificationDenied

ClassSource on GitHub

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Manager

ClassSource on GitHub

@property SessionHandlerInterface|null $adapter @property string $name @property array $options @property string $uniqueId

Uses InvalidArgumentException · Phalcon\Di\AbstractInjectionAware · Phalcon\Di\DiInterface · Phalcon\Session\Exceptions\InvalidSessionAdapter · Phalcon\Session\Exceptions\InvalidSessionId · Phalcon\Session\Exceptions\InvalidSessionName · Phalcon\Session\Exceptions\SessionAlreadyStarted · Phalcon\Session\Exceptions\SessionModificationDenied · Phalcon\Traits\Php\HeaderTrait · Phalcon\Traits\Support\Helper\Arr\GetTrait · SessionHandlerInterface

Method Summary

public__construct( array$options = [] )Manager constructor.publicmixed__get( string$key )Alias: Gets a session variable from an application contextpublicbool__isset( string$key )Alias: Check whether a session variable is set in an application contextpublicvoid__set(string$key,mixed$value)Alias: Sets a session variable in an application contextpublicvoid__unset( string$key )Alias: Removes a session variable from an application contextpublicvoiddestroy()Destroy/end a sessionpublicboolexists()Check whether the session has been startedpublicmixedget(string$key,mixed$defaultValue = null,bool$remove = false)Gets a session variable from an application contextpublicSessionHandlerInterface|nullgetAdapter()Returns the stored session adapterpublicstringgetId()Returns the session idpublicstringgetName()Returns the name of the sessionpublicarraygetOptions()Get internal optionspublicboolhas( string$key )Check whether a session variable is set in an application contextpublicManagerInterfaceregenerateId( bool$deleteOldSession = true )Regenerates the session id via session_regenerate_id() (when thepublicvoidremove( string$key )Removes a session variable from an application contextpublicvoidset(string$key,mixed$value)Sets a session variable in an application contextpublicManagerInterfacesetAdapter( SessionHandlerInterface$adapter )Set the adapter for the sessionpublicManagerInterfacesetId( string$sessionId )Set session IdpublicManagerInterfacesetName( string$name )Set the session name. Throw exception if the session has startedpublicvoidsetOptions( array$options )Sets session's optionspublicboolstart()Starts the session (if headers are already sent the session will not bepublicintstatus()Returns the status of the current session.

Methods

Public · 22

__construct()

public function __construct( array $options = [] );

Manager constructor.

__get()

public function __get( string $key ): mixed;

Alias: Gets a session variable from an application context

__isset()

public function __isset( string $key ): bool;

Alias: Check whether a session variable is set in an application context

__set()

public function __set(
    string $key,
    mixed $value
): void;

Alias: Sets a session variable in an application context

__unset()

public function __unset( string $key ): void;

Alias: Removes a session variable from an application context

destroy()

public function destroy(): void;

Destroy/end a session

exists()

public function exists(): bool;

Check whether the session has been started

get()

public function get(
    string $key,
    mixed $defaultValue = null,
    bool $remove = false
): mixed;

Gets a session variable from an application context

getAdapter()

public function getAdapter(): SessionHandlerInterface|null;

Returns the stored session adapter

getId()

public function getId(): string;

Returns the session id

getName()

public function getName(): string;

Returns the name of the session

getOptions()

public function getOptions(): array;

Get internal options

has()

public function has( string $key ): bool;

Check whether a session variable is set in an application context

regenerateId()

public function regenerateId( bool $deleteOldSession = true ): ManagerInterface;

Regenerates the session id via session_regenerate_id() (when the session is active). The registered save handler persists the data under the new id.

remove()

public function remove( string $key ): void;

Removes a session variable from an application context

set()

public function set(
    string $key,
    mixed $value
): void;

Sets a session variable in an application context

setAdapter()

public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;

Set the adapter for the session

setId()

public function setId( string $sessionId ): ManagerInterface;

Set session Id

setName()

public function setName( string $name ): ManagerInterface;

Set the session name. Throw exception if the session has started and do not allow poop names

setOptions()

public function setOptions( array $options ): void;

Sets session’s options

start()

public function start(): bool;

Starts the session (if headers are already sent the session will not be started)

status()

public function status(): int;

Returns the status of the current session.

Session\ManagerInterface

InterfaceSource on GitHub

Phalcon\Session

Interface for the Phalcon\Session\Manager

  • Phalcon\Session\ManagerInterface

Uses InvalidArgumentException · SessionHandlerInterface

Method Summary

publicmixed__get( string$key )Alias: Gets a session variable from an application contextpublicbool__isset( string$key )Alias: Check whether a session variable is set in an application contextpublicvoid__set(string$key,mixed$value)Alias: Sets a session variable in an application contextpublicvoid__unset( string$key )Alias: Removes a session variable from an application contextpublicvoiddestroy()Destroy/end a sessionpublicboolexists()Check whether the session has been startedpublicmixedget(string$key,mixed$defaultValue = null,bool$remove = false)Gets a session variable from an application contextpublicSessionHandlerInterface|nullgetAdapter()Returns the stored session adapterpublicstringgetId()Returns the session idpublicstringgetName()Returns the name of the sessionpublicarraygetOptions()Get internal optionspublicboolhas( string$key )Check whether a session variable is set in an application contextpublicManagerInterfaceregenerateId( bool$deleteOldSession = true )Regenerates the session id using the adapter.publicvoidremove( string$key )Removes a session variable from an application contextpublicvoidset(string$key,mixed$value)Sets a session variable in an application contextpublicManagerInterfacesetAdapter( SessionHandlerInterface$adapter )Set the adapter for the sessionpublicManagerInterfacesetId( string$sessionId )Set session IdpublicManagerInterfacesetName( string$name )Set the session name. Throw exception if the session has startedpublicvoidsetOptions( array$options )Sets session's optionspublicboolstart()Starts the session (if headers are already sent the session will not bepublicintstatus()Returns the status of the current session.

Constants

intSESSION_ACTIVE = 2
intSESSION_DISABLED = 0
intSESSION_NONE = 1

Methods

Public · 21

__get()

public function __get( string $key ): mixed;

Alias: Gets a session variable from an application context

__isset()

public function __isset( string $key ): bool;

Alias: Check whether a session variable is set in an application context

__set()

public function __set(
    string $key,
    mixed $value
): void;

Alias: Sets a session variable in an application context

__unset()

public function __unset( string $key ): void;

Alias: Removes a session variable from an application context

destroy()

public function destroy(): void;

Destroy/end a session

exists()

public function exists(): bool;

Check whether the session has been started

get()

public function get(
    string $key,
    mixed $defaultValue = null,
    bool $remove = false
): mixed;

Gets a session variable from an application context

getAdapter()

public function getAdapter(): SessionHandlerInterface|null;

Returns the stored session adapter

getId()

public function getId(): string;

Returns the session id

getName()

public function getName(): string;

Returns the name of the session

getOptions()

public function getOptions(): array;

Get internal options

has()

public function has( string $key ): bool;

Check whether a session variable is set in an application context

regenerateId()

public function regenerateId( bool $deleteOldSession = true ): ManagerInterface;

Regenerates the session id using the adapter.

remove()

public function remove( string $key ): void;

Removes a session variable from an application context

set()

public function set(
    string $key,
    mixed $value
): void;

Sets a session variable in an application context

setAdapter()

public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;

Set the adapter for the session

setId()

public function setId( string $sessionId ): ManagerInterface;

Set session Id

setName()

public function setName( string $name ): ManagerInterface;

Set the session name. Throw exception if the session has started and do not allow poop names

setOptions()

public function setOptions( array $options ): void;

Sets session’s options

start()

public function start(): bool;

Starts the session (if headers are already sent the session will not be started)

status()

public function status(): int;

Returns the status of the current session.

Type to search…

↑↓ navigate↵ selectEsc close