3 * Phar stub file for indieauth-openid. Handles startup of the .phar file.
5 if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
6 echo "Phar extension not avaiable\n";
10 $web = 'www/index.php';
13 * Rewrite the HTTP request path to an internal file.
14 * Maps "" and "/" to "www/index.php".
16 * @param string $path Path from the browser, relative to the .phar
18 * @return string Internal path.
20 function rewritePath($path)
23 //we need a / to get the relative links on index.php work
24 if (!isset($_SERVER['REQUEST_SCHEME'])) {
25 $_SERVER['REQUEST_SCHEME'] = 'http';
27 $url = $_SERVER['REQUEST_SCHEME'] . '://'
28 . $_SERVER['HTTP_HOST']
29 . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
31 header('Location: ' . $url);
33 } else if ($path == '/') {
34 return 'www/index.php';
37 if (substr($path, -4) == '.css') {
38 header('Expires: ' . date('r', time() + 86400 * 7));
43 if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
44 //work around https://bugs.php.net/bug.php?id=51918
45 header('IndieAuth: authorization_endpoint');
51 . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
53 Phar::webPhar(null, $web, null, array(), 'rewritePath');
55 //TODO: implement CLI setup check
56 echo "indieauth-openid can only be used in the browser\n";