Browse Source

Auth files

Maurits van der Schee 10 years ago
parent
commit
5e38ff5d0f
2 changed files with 43 additions and 0 deletions
  1. 32
    0
      auth.php
  2. 11
    0
      auth_example.php

+ 32
- 0
auth.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+$ch = curl_init();
4
+curl_setopt($ch, CURLOPT_URL,"http://10.11.25.107/auth_basic.php");
5
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
6
+
7
+$headers = apache_request_headers();
8
+
9
+if (!isset($headers['Authorization'])) die('Forbidden');
10
+
11
+$headers = array('Authorization: '.$headers['Authorization']);
12
+
13
+curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
14
+
15
+$server_output = curl_exec ($ch);
16
+$info = curl_getinfo($ch);
17
+curl_close ($ch);
18
+
19
+if ($info['http_code']!=200) die('Forbidden');
20
+
21
+include "api.php";
22
+
23
+header('Access-Control-Allow-Origin: *');
24
+$api = new SQLSRV_CRUD_API(array(
25
+  'hostname'=>'(local)',
26
+  'username'=>'',
27
+  'password'=>'',
28
+  'database'=>'xxx',
29
+  'charset'=>'UTF-8'
30
+));
31
+$api->executeCommand();
32
+

+ 11
- 0
auth_example.php View File

@@ -0,0 +1,11 @@
1
+<?php
2
+if (!isset($_SERVER['PHP_AUTH_USER'])) {
3
+    header('WWW-Authenticate: Basic realm="My Realm"');
4
+    header('HTTP/1.0 401 Unauthorized');
5
+    echo 'Text to send if user hits Cancel button';
6
+    exit;
7
+} elseif ($_SERVER['PHP_AUTH_USER']=='user' && $_SERVER['PHP_AUTH_PW']=='pass') {
8
+    echo "OK";
9
+} else {
10
+    header('HTTP/1.0 403 Forbidden');
11
+}

Loading…
Cancel
Save