Skip to content

Commit ffa3021

Browse files
committed
Updated
1 parent 7f6ef35 commit ffa3021

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

docs/session.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
This `Session` class allows you to manage sessions in your application.
33

44
## Method `Session::start()`.
5-
This static method is responsible for initializing the session. Check if the session is already active.
6-
If the session is not active, log in with the following options:
5+
This static method is responsible for initializing the session.
6+
7+
By default this method initializes the session by setting the following options:
78
- "name": "mk4u"
9+
- "use_cookies": true,
810
- "use_only_cookies": true
911
- "cookie_lifetime": 0
1012
- "cookie_httponly": true
1113
- "cookie_secure": true
1214
- "use_strict_mode": true
1315

16+
But you can change these values to suit your use case
17+
[read more 👀](https://www.php.net/manual/es/session.configuration.php)
18+
1419
Returns true if the session is successfully started
1520

1621
```php
@@ -29,7 +34,7 @@ Session::set('hello', 'Hello World!');
2934
```
3035

3136
## Method `Session::get(?string $name = null, mixed $default = null)`.
32-
This static method retrieves the values stored in `$_SESSION`. It can return the value of a specific session or all values of `$_SESSION` if no name is provided. If the session name does not exist and no value is specified for `$default`, this method throws an exception of type `RuntimeException`; otherwise, it will return the default value.
37+
This static method retrieves the values stored in $_SESSION that match the name passed. It may return the value of the superglobal $_SESSION if a value for name is not provided. If the session name does not exist, this method returns the value of $default.
3338

3439
**Parameters:**
3540
- `$name` (string|null): The name of the session variable to retrieve. Default is `null`.
@@ -48,7 +53,7 @@ Session::get('unavailable','value');
4853
// return "value"
4954

5055
Session::get('unavailable');
51-
//Fatal error: Uncaught RuntimeException: The session 'unavailable' does not exist
56+
//return null
5257
```
5358

5459
## Method `Session::has(string $name)`.
@@ -59,7 +64,7 @@ Session::has('hello');
5964
```
6065

6166
## Method `Session::remove(string $name)`.
62-
This method deletes a specified session.
67+
This method deletes a specified session.
6368

6469
```php
6570
Session::remove('hello');
@@ -83,8 +88,40 @@ Session::id();
8388
```
8489

8590
## Method `Session::destroy()`.
86-
Este método desestablece todas las variables de sesión y destruye la sesión
91+
This method deletes all session variables and destroys the session.
8792

8893
```php
8994
Session::destroy();
95+
```
96+
97+
## Method `Session::delete(string $name)`.
98+
Alias to remove.
99+
100+
```php
101+
Session::delete('hello');
102+
```
103+
104+
## Method `Session::flash(string $name, mixed $value = null)`.
105+
This method sets a flash message in the session cookie, the data stored in the session using this method will be available immediately and during the subsequent HTTP request. After the subsequent HTTP request, the detailed data will be deleted.
106+
107+
**Parameters:**
108+
- `$name` (string): The name of the message identifier to set.
109+
- `$value` (mixed): The value to assign to the flash message. Default is `null`.
110+
111+
### Set a session message
112+
To store a flash message just call the `Session::flash()` method and pass the name and the message.
113+
114+
```php
115+
Session::flash('message','Hello Word!!');
116+
```
117+
118+
### Return a session message
119+
To return the message just call the `Session::flash()` method but this time just provide the name.
120+
121+
> [!NOTE]
122+
> Remember that `Session::flash()` will only return the flash message once after that it is deleted.
123+
124+
```php
125+
echo Session::flash('message');
126+
// Hello Word!!
90127
```

0 commit comments

Comments
 (0)