ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
basicauth.php
Go to the documentation of this file.
1<?php
2
11 "user1" => "password",
12 "user2" => "password",
13];
14
18
19// Find the autoloader
21 __DIR__ . '/../vendor/autoload.php',
22 __DIR__ . '/../../../autoload.php',
23 __DIR__ . '/vendor/autoload.php',
24
25];
26
27foreach ($paths as $path) {
28 if (file_exists($path)) {
29 include $path;
30 break;
31 }
32}
33
34$request = Sapi::getRequest();
36
37$basicAuth = new Auth\Basic("Locked down area", $request, $response);
38if (!$userPass = $basicAuth->getCredentials()) {
39
40 // No username or password given
41 $basicAuth->requireLogin();
42
43} elseif (!isset($userList[$userPass[0]]) || $userList[$userPass[0]] !== $userPass[1]) {
44
45 // Username or password are incorrect
46 $basicAuth->requireLogin();
47} else {
48
49 // Success !
50 $response->setBody('You are logged in!');
51
52}
53
54// Sending the response
55Sapi::sendResponse($response);
$path
Definition: aliased.php:25
$paths
Definition: basicauth.php:20
foreach($paths as $path) $request
Definition: basicauth.php:34
$userList
This example shows how to do Basic authentication.
Definition: basicauth.php:10
$basicAuth
Definition: basicauth.php:37
$response
Definition: basicauth.php:35
An exception for terminatinating execution or to throw for unit testing.
This class represents a single HTTP response.
Definition: Response.php:12
PHP SAPI.
Definition: Sapi.php:31