| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\SessionException; |
| 6 |
|
| 7 |
/** |
| 8 |
* session_abort finishes session without saving |
| 9 |
* data. Thus the original values in session data are kept. |
| 10 |
* |
| 11 |
* @throws SessionException |
| 12 |
* |
| 13 |
*/ |
| 14 |
function session_abort(): void |
| 15 |
{ |
| 16 |
error_clear_last(); |
| 17 |
$result = \session_abort(); |
| 18 |
if ($result === false) { |
| 19 |
throw SessionException::createFromPhpError(); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* session_decode decodes the serialized session data provided in |
| 26 |
* $data, and populates the $_SESSION superglobal |
| 27 |
* with the result. |
| 28 |
* |
| 29 |
* By default, the unserialization method used is internal to PHP, and is not the same as unserialize. |
| 30 |
* The serialization method can be set using session.serialize_handler. |
| 31 |
* |
| 32 |
* @param string $data The encoded data to be stored. |
| 33 |
* @throws SessionException |
| 34 |
* |
| 35 |
*/ |
| 36 |
function session_decode(string $data): void |
| 37 |
{ |
| 38 |
error_clear_last(); |
| 39 |
$result = \session_decode($data); |
| 40 |
if ($result === false) { |
| 41 |
throw SessionException::createFromPhpError(); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* In order to kill the session altogether, the |
| 48 |
* session ID must also be unset. If a cookie is used to propagate the |
| 49 |
* session ID (default behavior), then the session cookie must be deleted. |
| 50 |
* setcookie may be used for that. |
| 51 |
* |
| 52 |
* When session.use_strict_mode |
| 53 |
* is enabled. You do not have to remove obsolete session ID cookie because |
| 54 |
* session module will not accept session ID cookie when there is no |
| 55 |
* data associated to the session ID and set new session ID cookie. |
| 56 |
* Enabling session.use_strict_mode |
| 57 |
* is recommended for all sites. |
| 58 |
* |
| 59 |
* @throws SessionException |
| 60 |
* |
| 61 |
*/ |
| 62 |
function session_destroy(): void |
| 63 |
{ |
| 64 |
error_clear_last(); |
| 65 |
$result = \session_destroy(); |
| 66 |
if ($result === false) { |
| 67 |
throw SessionException::createFromPhpError(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
/** |
| 73 |
* session_regenerate_id will replace the current |
| 74 |
* session id with a new one, and keep the current session information. |
| 75 |
* |
| 76 |
* When session.use_trans_sid |
| 77 |
* is enabled, output must be started after session_regenerate_id |
| 78 |
* call. Otherwise, old session ID is used. |
| 79 |
* |
| 80 |
* @param bool $delete_old_session Whether to delete the old associated session file or not. |
| 81 |
* You should not delete old session if you need to avoid |
| 82 |
* races caused by deletion or detect/avoid session hijack |
| 83 |
* attacks. |
| 84 |
* @throws SessionException |
| 85 |
* |
| 86 |
*/ |
| 87 |
function session_regenerate_id(bool $delete_old_session = false): void |
| 88 |
{ |
| 89 |
error_clear_last(); |
| 90 |
$result = \session_regenerate_id($delete_old_session); |
| 91 |
if ($result === false) { |
| 92 |
throw SessionException::createFromPhpError(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
/** |
| 98 |
* session_reset reinitializes a session with |
| 99 |
* original values stored in session storage. This function requires an active session and |
| 100 |
* discards changes in $_SESSION. |
| 101 |
* |
| 102 |
* @throws SessionException |
| 103 |
* |
| 104 |
*/ |
| 105 |
function session_reset(): void |
| 106 |
{ |
| 107 |
error_clear_last(); |
| 108 |
$result = \session_reset(); |
| 109 |
if ($result === false) { |
| 110 |
throw SessionException::createFromPhpError(); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
* The session_unset function frees all session variables |
| 117 |
* currently registered. |
| 118 |
* |
| 119 |
* @throws SessionException |
| 120 |
* |
| 121 |
*/ |
| 122 |
function session_unset(): void |
| 123 |
{ |
| 124 |
error_clear_last(); |
| 125 |
$result = \session_unset(); |
| 126 |
if ($result === false) { |
| 127 |
throw SessionException::createFromPhpError(); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
/** |
| 133 |
* End the current session and store session data. |
| 134 |
* |
| 135 |
* Session data is usually stored after your script terminated without the |
| 136 |
* need to call session_write_close, but as session data |
| 137 |
* is locked to prevent concurrent writes only one script may operate on a |
| 138 |
* session at any time. When using framesets together with sessions you will |
| 139 |
* experience the frames loading one by one due to this locking. You can |
| 140 |
* reduce the time needed to load all the frames by ending the session as |
| 141 |
* soon as all changes to session variables are done. |
| 142 |
* |
| 143 |
* @throws SessionException |
| 144 |
* |
| 145 |
*/ |
| 146 |
function session_write_close(): void |
| 147 |
{ |
| 148 |
error_clear_last(); |
| 149 |
$result = \session_write_close(); |
| 150 |
if ($result === false) { |
| 151 |
throw SessionException::createFromPhpError(); |
| 152 |
} |
| 153 |
} |
| 154 |
|