Slim Basic Authentication

Viewed 15223

Good day everyone!

I have a working slim code here with slim-basic-auth and when I go to a restricted directory, this shows up:

enter image description here

Everything works, but what I wanted to do is to redirect it to my login page instead of showing a popup login box. Here is my login page:

enter image description here

My slim code:

$pdo = new \PDO("mysql:host=localhost;dbname=databasename", "username");
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
    "path" => "/main",
    "realm" => "Protected",
    "authenticator" => new PdoAuthenticator([
        "pdo" => $pdo,
        "table" => "accounts",
        "user" => "accountUsername",
        "hash" => "accountPassword"
    ]),
    "callback" => function ($request, $response, $arguments) use ($app) {
        return $response->withRedirect('/main/contacts');
    }

When I try to login using the popup login box, it works but I really want to redirect it to my login page instead of that.

Any help would be much appreciated.

2 Answers
Related