Skip to content

Phalcon session

NOTE

All classes are prefixed with Phalcon

Session\Adapter\AbstractAdapter

Abstract Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Storage\Adapter\AdapterInterface · SessionHandlerInterface

Method Summary

Properties

protected AdapterInterface $adapter

Methods

Public · 6

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

write()

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

Write

Protected · 1

getArrVal()

protected function getArrVal(
    array $collection,
    mixed $index,
    mixed $defaultValue = null
): mixed;

@todo Remove this when we get traits

Session\Adapter\Exceptions\AdapterRuntimeError

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Session\Adapter\Exceptions\InvalidSavePath

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Adapter\Exceptions\SavePathUnavailable

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $path );

Session\Adapter\Libmemcached

Class Source 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-'

]

Session\Adapter\Noop

Class Source 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

Method Summary

Methods

Public · 6

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

write()

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

Write

Session\Adapter\Redis

Class Source on GitHub

Phalcon\Session\Adapter\Redis

Uses Phalcon\Storage\AdapterFactory

Method Summary

Methods

Public · 1

__construct()

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

Constructor

Session\Adapter\Stream

Class Source 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

Method Summary

Properties

protected array $options = [] Session options
protected string $prefix = "" Session prefix

Methods

Public · 6

__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

write()

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

getArrVal()

protected function getArrVal(
    array $collection,
    mixed $index,
    mixed $defaultValue = null,
    string $cast = null
): mixed;

@todo Remove this when we get traits

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

phpFileExists()

protected function phpFileExists( string $filename );

@link https://php.net/manual/en/function.file-exists.php

phpFileGetContents()

protected function phpFileGetContents( string $filename );

@link https://php.net/manual/en/function.file-get-contents.php

phpFilePutContents()

protected function phpFilePutContents(
    string $filename,
    mixed $data,
    int $flags = 0,
    mixed $context = null
);

@link https://php.net/manual/en/function.file-put-contents.php

phpFopen()

protected function phpFopen(
    string $filename,
    string $mode
);

@link https://php.net/manual/en/function.fopen.php

phpIniGet()

protected function phpIniGet( string $varname ): string;

Gets the value of a configuration option

@link https://php.net/manual/en/function.ini-get.php @link https://php.net/manual/en/ini.list.php

phpIsWritable()

protected function phpIsWritable( string $filename ): bool;

Tells whether the filename is writable

@link https://php.net/manual/en/function.is-writable.php

Session\Bag

Class Source 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

Interface Source 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

Class Source on GitHub

Phalcon\Session\Exception

Exceptions thrown in Phalcon\Session will use this class

Session\Exceptions\InvalidSessionAdapter

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\InvalidSessionName

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\SessionAlreadyStarted

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Exceptions\SessionModificationDenied

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Uses Phalcon\Session\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Session\Manager

Class Source 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\InvalidSessionName · Phalcon\Session\Exceptions\SessionAlreadyStarted · Phalcon\Session\Exceptions\SessionModificationDenied · SessionHandlerInterface

Method Summary

public __construct( array $options = [] ) Manager constructor. public mixed __get( string $key ) Alias: Gets a session variable from an application context public bool __isset( string $key ) Alias: Check whether a session variable is set in an application context public void __set(string $key,mixed $value) Alias: Sets a session variable in an application context public void __unset( string $key ) Alias: Removes a session variable from an application context public void destroy() Destroy/end a session public bool exists() Check whether the session has been started public mixed get(string $key,mixed $defaultValue = null,bool $remove = false) Gets a session variable from an application context public SessionHandlerInterface|null getAdapter() Returns the stored session adapter public string getId() Returns the session id public string getName() Returns the name of the session public array getOptions() Get internal options public bool has( string $key ) Check whether a session variable is set in an application context public ManagerInterface regenerateId( bool $deleteOldSession = true ) Regenerates the session id using the adapter. public void remove( string $key ) Removes a session variable from an application context public void set(string $key,mixed $value) Sets a session variable in an application context public ManagerInterface setAdapter( SessionHandlerInterface $adapter ) Set the adapter for the session public ManagerInterface setId( string $sessionId ) Set session Id public ManagerInterface setName( string $name ) Set the session name. Throw exception if the session has started public void setOptions( array $options ) Sets session's options public bool start() Starts the session (if headers are already sent the session will not be public int status() Returns the status of the current session. protected bool phpHeadersSent() Checks if or where headers have been sent

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 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.

Protected · 1

phpHeadersSent()

protected function phpHeadersSent(): bool;

Checks if or where headers have been sent

@link https://php.net/manual/en/function.headers-sent.php

Session\ManagerInterface

Interface Source on GitHub

Phalcon\Session

Interface for the Phalcon\Session\Manager

  • Phalcon\Session\ManagerInterface

Uses InvalidArgumentException · SessionHandlerInterface

Method Summary

public mixed __get( string $key ) Alias: Gets a session variable from an application context public bool __isset( string $key ) Alias: Check whether a session variable is set in an application context public void __set(string $key,mixed $value) Alias: Sets a session variable in an application context public void __unset( string $key ) Alias: Removes a session variable from an application context public void destroy() Destroy/end a session public bool exists() Check whether the session has been started public mixed get(string $key,mixed $defaultValue = null,bool $remove = false) Gets a session variable from an application context public SessionHandlerInterface|null getAdapter() Returns the stored session adapter public string getId() Returns the session id public string getName() Returns the name of the session public array getOptions() Get internal options public bool has( string $key ) Check whether a session variable is set in an application context public ManagerInterface regenerateId( bool $deleteOldSession = true ) Regenerates the session id using the adapter. public void remove( string $key ) Removes a session variable from an application context public void set(string $key,mixed $value) Sets a session variable in an application context public ManagerInterface setAdapter( SessionHandlerInterface $adapter ) Set the adapter for the session public ManagerInterface setId( string $sessionId ) Set session Id public ManagerInterface setName( string $name ) Set the session name. Throw exception if the session has started public void setOptions( array $options ) Sets session's options public bool start() Starts the session (if headers are already sent the session will not be public int status() Returns the status of the current session.

Constants

int SESSION_ACTIVE = 2
int SESSION_DISABLED = 0
int SESSION_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.