PHP code example of germania-kg / redirect-unauthorized

1. Go to this page and download the library: Download germania-kg/redirect-unauthorized 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/ */

    

germania-kg / redirect-unauthorized example snippets



class MyRedirector exends Germania\RedirectUnauthorized\Middleware
{
    /**
     * HTTP Status Code for Redirection
     * @var string
     */
    public $redirect_status_code  = 301;
    
    /**
     * HTTP Status Code for "Unauthorized". Usually 401.
     * @var string
     */
    public $auth_


use Germania\RedirectUnauthorized\Middleware;

// Aura.Session Segment
$session_factory = new \Aura\Session\SessionFactory;
$session = $session_factory->newInstance($_COOKIE);
$segment = $session->getSegment('Vendor\Package\ClassName');

// Where to redirect unauthorized requests to
$login_url = "/login.html"

// Optional: PSR-3 Logger
$logger = new Monolog

$middleware = new Middleware( $segment, $login_url);
$middleware = new Middleware( $segment, $login_url, $logger);



use Germania\RedirectUnauthorized\Middleware;

$app = new Slim\App;
$app->add( new Middleware );