]> 91.132.146.200 Git - dolphin.git/commitdiff
php authentication methods and examples. http auth
authorBanana <banana@starscream.de>
Wed, 4 Apr 2012 11:41:23 +0000 (13:41 +0200)
committerBanana <banana@starscream.de>
Wed, 4 Apr 2012 11:41:23 +0000 (13:41 +0200)
authentication/README [new file with mode: 0644]
authentication/http-auth.php [new file with mode: 0644]

diff --git a/authentication/README b/authentication/README
new file mode 100644 (file)
index 0000000..e12144e
--- /dev/null
@@ -0,0 +1 @@
+Simple examples about some authentication methods / user login in PHP
\ No newline at end of file
diff --git a/authentication/http-auth.php b/authentication/http-auth.php
new file mode 100644 (file)
index 0000000..5ad1eca
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ *  dolphin. Collection of useful PHP skeletons.
+ *  Copyright (C) 2012  Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * simple HTTP auth method with PHP
+ * more details can be found here:
+ * http://php.net/manual/en/features.http-auth.php
+ */
+
+if (!isset($_SERVER['PHP_AUTH_USER'])) {
+    header('WWW-Authenticate: Basic realm="My secret base"');
+    header('HTTP/1.0 401 Unauthorized');
+    echo 'You canceled the auth process. Reload the page to get the box again.';
+    exit;
+} else {
+    echo "<p>Hello ".$_SERVER['PHP_AUTH_USER'].".</p>";
+    echo "<p>You entered ".$_SERVER['PHP_AUTH_PW']." as your password.</p>";
+}
+?>
\ No newline at end of file