Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1821547
basicauth.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
1 KB
Subscribers
None
basicauth.php
View Options
<?php
/**
* This example shows how to do Basic authentication.
* *
* @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
$userList
=
[
"user1"
=>
"password"
,
"user2"
=>
"password"
,
];
use
Sabre\HTTP\Sapi
;
use
Sabre\HTTP\Response
;
use
Sabre\HTTP\Auth
;
// Find the autoloader
$paths
=
[
__DIR__
.
'/../vendor/autoload.php'
,
__DIR__
.
'/../../../autoload.php'
,
__DIR__
.
'/vendor/autoload.php'
,
];
foreach
(
$paths
as
$path
)
{
if
(
file_exists
(
$path
))
{
include
$path
;
break
;
}
}
$request
=
Sapi
::
getRequest
();
$response
=
new
Response
();
$basicAuth
=
new
Auth\Basic
(
"Locked down area"
,
$request
,
$response
);
if
(!
$userPass
=
$basicAuth
->
getCredentials
())
{
// No username or password given
$basicAuth
->
requireLogin
();
}
elseif
(!
isset
(
$userList
[
$userPass
[
0
]])
||
$userList
[
$userPass
[
0
]]
!==
$userPass
[
1
])
{
// Username or password are incorrect
$basicAuth
->
requireLogin
();
}
else
{
// Success !
$response
->
setBody
(
'You are logged in!'
);
}
// Sending the response
Sapi
::
sendResponse
(
$response
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Dec 24, 3:03 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
915352
Default Alt Text
basicauth.php (1 KB)
Attached To
rDAVCAL DokuWiki DAVCal PlugIn
Event Timeline
Log In to Comment