1. Go to this page and download the library: Download josantonius/session 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/ */
josantonius / session example snippets
/**
* @throws HeadersSentException if headers already sent.
* @throws SessionStartedException if session already started.
* @throws WrongSessionOptionException if setting options failed.
*
* @see https://php.net/session.configuration for List of available $options.
*/
public function start(array $options = []): bool;
public function isStarted(): bool;
/**
* @throws SessionNotStartedException if session was not started.
*/
public function set(string $name, mixed $value): void;
/**
* Optionally defines a default value when the attribute does not exist.
*/
public function get(string $name, mixed $default = null): mixed;
public function all(): array;
public function has(string $name): bool;
/**
* If attributes exist they are replaced, if they do not exist they are created.
*
* @throws SessionNotStartedException if session was not started.
*/
public function replace(array $data): void;
/**
* Optionally defines a default value when the attribute does not exist.
*
* @throws SessionNotStartedException if session was not started.
*/
public function pull(string $name, mixed $default = null): mixed;
/**
* @throws SessionNotStartedException if session was not started.
*/
public function remove(string $name): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public function clear(): void;
public function getId(): string;
/**
* @throws SessionStartedException if session already started.
*/
public function setId(string $sessionId): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public function regenerateId(bool $deleteOldSession = false): bool;
public function getName(): string;
/**
* @throws SessionStartedException if session already started.
*/
public function setName(string $name): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public function destroy(): bool;
/**
* @throws HeadersSentException if headers already sent.
* @throws SessionStartedException if session already started.
* @throws WrongSessionOptionException if setting options failed.
*
* @see https://php.net/session.configuration for List of available $options.
*/
public static function start(array $options = []): bool;
public static function isStarted(): bool;
/**
* @throws SessionNotStartedException if session was not started.
*/
public static function set(string $name, mixed $value): void;
/**
* Optionally defines a default value when the attribute does not exist.
*/
public static function get(string $name, mixed $default = null): mixed;
public static function all(): array;
public static function has(string $name): bool;
/**
* If attributes exist they are replaced, if they do not exist they are created.
*
* @throws SessionNotStartedException if session was not started.
*/
public static function replace(array $data): void;
/**
* Optionally defines a default value when the attribute does not exist.
*
* @throws SessionNotStartedException if session was not started.
*/
public static function pull(string $name, mixed $default = null): mixed;
/**
* @throws SessionNotStartedException if session was not started.
*/
public static function remove(string $name): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public static function clear(): void;
public static function getId(): string;
/**
* @throws SessionStartedException if session already started.
*/
public static function setId(string $sessionId): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public static function regenerateId(bool $deleteOldSession = false): bool;
public static function getName(): string;
/**
* @throws SessionStartedException if session already started.
*/
public static function setName(string $name): void;
/**
* @throws SessionNotStartedException if session was not started.
*/
public static function destroy(): bool;
use Josantonius\Session\Exceptions\HeadersSentException;
use Josantonius\Session\Exceptions\SessionException;
use Josantonius\Session\Exceptions\SessionNotStartedException;
use Josantonius\Session\Exceptions\SessionStartedException;
use Josantonius\Session\Exceptions\WrongSessionOptionException;
use Josantonius\Session\Session;
$session = new Session();
$session->start();
use Josantonius\Session\Facades\Session;
Session::start();