PHP code example of mohdraquib / laravel-secure-middleware

1. Go to this page and download the library: Download mohdraquib/laravel-secure-middleware 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/ */

    

mohdraquib / laravel-secure-middleware example snippets


use MohdRaquib\SecureMiddleware\AlwaysUseHTTPS;
use MohdRaquib\SecureMiddleware\EnableHSTS;
use MohdRaquib\SecureMiddleware\ForceNonWWW;
// or use ForceWWW instead of ForceNonWWW

protected $middleware = [
    // ...
    AlwaysUseHTTPS::class,
    EnableHSTS::class,
    ForceNonWWW::class, // or ForceWWW::class
];

protected $routeMiddleware = [
    'https.redirect' => \MohdRaquib\SecureMiddleware\AlwaysUseHTTPS::class,
    'hsts' => \MohdRaquib\SecureMiddleware\EnableHSTS::class,
    'remove.www' => \MohdRaquib\SecureMiddleware\ForceNonWWW::class,
    'force.www' => \MohdRaquib\SecureMiddleware\ForceWWW::class,
];

Route::get('/secure', function () {
    return 'Secure Route';
})->middleware(['https.redirect', 'hsts', 'remove.www']);