You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-44Lines changed: 15 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,9 @@ A simple, lightweight, and powerful PHP Router with rich features like Middlewar
16
16
17
17
- Supports `GET``POST``PUT``PATCH` and `DELETE` HTTPS verbs
18
18
- The methods that the router supports are - `get()``post()``put()``patch()``delete()``match()``any()`
19
-
- Named Routes
20
19
- Middleware
20
+
- Controller
21
+
- Named Routes
21
22
- Regular Expression Constraints for parameters
22
23
- Fallback method
23
24
- Easy way to manage request
@@ -33,6 +34,7 @@ A simple, lightweight, and powerful PHP Router with rich features like Middlewar
33
34
-**[Directories](#Directories)**
34
35
-**[Routes](#Routes)**
35
36
-**[Middlewares](#middlewares)**
37
+
-**[CSRF Protection](#CSRF-Protection)**
36
38
-**[Controllers](#Controllers)**
37
39
-**[Request](#Request)**
38
40
-**[Handle Html View Content File](#Handle-Html-View-Content-File)**
@@ -414,17 +416,6 @@ If you are defining a route that redirects to another URI, you may use the `redi
414
416
$router->redirect('/here', '/there');
415
417
```
416
418
417
-
## CSRF Protection:
418
-
419
-
Remember, any HTML forms pointing to POST, PUT, PATCH, or DELETE routes that are defined in the web routes file should include a CSRF token field. Otherwise, the request will be rejected:
420
-
421
-
```php
422
-
<formmethod="POST"action="/profile">
423
-
<?=setCsrf()?>
424
-
...
425
-
</form>
426
-
```
427
-
428
419
## Middlewares:
429
420
430
421
`app/Middlewares`: Middleware provides a convenient mechanism for inspecting and filtering HTTP requests entering your application.
public function handle(Request $request, array $guards) {
520
-
if (!empty($guards)) {
521
-
// Handle middleware arguments.
522
-
foreach ($guards as $guard) {
523
-
if (!Auth::guard($guard)->check() && $guard === 'admin') {
524
-
return redirect('/admin/login');
525
-
}
526
-
}
527
-
} elseif (!Auth::check()) {
528
-
return redirect('/login');
529
-
}
530
-
return;
531
-
}
532
-
``` -->
533
-
534
493
#### Set default middlewares:
535
494
536
495
If you want to set some middleware to Https verbs by default, you can do that very easily, The defined middleware will run when that https method request is handled:
@@ -545,6 +504,18 @@ Open `app/config/middleware.php`
545
504
'delete' => [ 'csrf', 'auth' ],
546
505
```
547
506
507
+
## CSRF Protection:
508
+
509
+
Anytime you define a "POST", "PUT", "PATCH", or "DELETE" HTML form in your application, you should include a hidden CSRF _token field in the form so that the CSRF protection middleware can validate the request, Otherwise, the request will be rejected. For convenience, you may use the `setCsrf()` function to generate the hidden token input field:
510
+
511
+
512
+
```php
513
+
<formmethod="POST"action="/profile">
514
+
<?=setCsrf()?>
515
+
...
516
+
</form>
517
+
```
518
+
548
519
## Controllers:
549
520
550
521
`app/Controllers`: Controllers respond to user actions (submitting forms, show users, view data, and any action etc.). Controllers are classes that extend the BaseController class.
0 commit comments