1. Go to this page and download the library: Download israel-nogueira/sky-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/ */
israel-nogueira / sky-session example snippets
use IsraelNogueira\SkySession\Session;
// Criar instância
$session = new Session();
// Definir valores
$session->set('username', 'john_doe');
$session->set('user_data', [
'email' => '[email protected]',
'role' => 'admin'
]);
// Recuperar valores
echo $session->get('username'); // john_doe
$userData = $session->get('user_data');
// Verificar existência
if ($session->has('username')) {
echo 'Usuário logado!';
}
// Remover valor
$session->unset('username');
// Obter todas as variáveis
$all = $session->all();
use IsraelNogueira\SkySession\Session;
$session = new Session();
// Set usando propriedade
$session->username = 'jane_doe';
$session->cart = ['item1', 'item2'];
// Get usando propriedade
echo $session->username; // jane_doe
print_r($session->cart);
// Isset
if (isset($session->username)) {
echo 'Username existe!';
}
// Unset
unset($session->cart);
use IsraelNogueira\SkySession\Session;
// Set
Session::username('admin');
Session::preferences(['theme' => 'dark', 'lang' => 'pt-BR']);
// Get
echo Session::username(); // admin
$prefs = Session::preferences();
// Unset (passando null)
Session::username(null);
// Múltiplos argumentos
Session::data('arg1', 'arg2', 'arg3'); // armazena como array
use IsraelNogueira\SkySession\Session;
// Primeira chamada cria a instância
$session1 = Session::getInstance(['secure' => true]);
// Próximas chamadas retornam a mesma instância
$session2 = Session::getInstance();
// $session1 === $session2 (true)
use IsraelNogueira\SkySession\Session;
$session = new Session();
// Regenerar ID (recomendado após login)
if ($loginSuccess) {
$session->regenerateId();
$session->set('authenticated', true);
}
use IsraelNogueira\SkySession\Session;
$session = new Session();
// Logout completo
$session->destroy();
// Remove todos os dados, cookies e destrói a sessão
use IsraelNogueira\SkySession\Session;
// Para desenvolvimento ou quando criptografia não é necessária
$session = new Session(['secure' => false]);
$session->set('debug', 'visible data');
// Dados ficam visíveis em $_SESSION
// Chamadas dinâmicas
Session::variableName($value); // Set
Session::variableName(); // Get
Session::variableName(null); // Unset
// Métodos com prefixo __
Session::__set($key, $value);
Session::__get($key);
Session::__regenerateId();
Session::__destroy();