Created
July 21, 2017 11:57
-
-
Save thomasnordquist/5b94d4ae0c7213e233c833ff9572d7b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This script tests if the authentication header is received, | |
// it does so by creating a request with authentication and printing the response. | |
// Location of the php fiel on the server | |
$protocol = (isset($_SERVER['HTTPS']) ? "https" : "http"); | |
$credentials = "username:password"; // Using inline credentials | |
$url = $protocol . '://' . $credentials . '@' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
if (!isset($_GET['test'])) { | |
// Perform self-test by calling the same url | |
$testUrl = $url . '?test=true'; | |
echo 'curl command <pre>curl '. $testUrl .'</pre>'; | |
$response = file_get_contents($testUrl); | |
echo '<h1>Response:</h1>'; | |
echo '<div style="border: 1px solid black">'. $response . '</div>'; | |
} else { | |
// Test if auth header has been received | |
$headers = apache_request_headers(); | |
if (isset($headers['Authorization'])) { | |
echo '<b>Authorization header received</b>'; | |
} else { | |
echo '<b>There is no "Authorization" header</b>'; | |
} | |
echo '<br /><br />Received headers: <br /><pre>' . print_r($headers, true) . '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment