session_encode
(PHP 4, PHP 5)
session_encode — Encodes the current session data as a string
Описание
string session_encode
( void
)
session_encode() returns a string with the contents of the current session encoded within.
Возвращаемые значения
Returns the contents of the current session encoded.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с сессиями
- Управление сессиями
- session_abort
- session_cache_expire
- session_cache_limiter
- session_commit
- session_create_id
- session_decode
- session_destroy
- session_encode
- session_gc
- session_get_cookie_params
- session_id
- session_is_registered
- session_module_name
- session_name
- session_regenerate_id
- session_register_shutdown
- session_register
- session_reset
- session_save_path
- session_set_cookie_params
- session_set_save_handler
- session_start
- session_status
- session_unregister
- session_unset
- session_write_close
Коментарии
session_encode() just return the session dataset in a formatted form
session_start();
$_SESSION['login_ok'] = true;
$_SESSION['nome'] = 'sica';
$_SESSION['inteiro'] = 34;
echo session_encode();
this code will print
login_ok|b:1;nome|s:4:"sica";inteiro|i:34;
session_encode() can't handle pipes in your keys.
<?php
session_start();
$_SESSION = ['foo|bar'=>'ba;z']; pathetic
dump(session_encode()); // false because "foo|bar" contains a pipe
?>
The session_encode and session_decode functions are incomplete.
Because there is no option to collect the output values for session_decode or input an array in session_encode.
I faced this issue while trying to implement custom session using session_set_save_handler.
It led me to limit the functionality to particular serialize_handler and had to hardcode the encode and decode functions like serialize and unserialize for option ['serialize_handler' => 'php_serialize'] instead of session_encode and session_decode once i am done with defining the encoding algo.