23,6 → 23,9 |
/** Identifiant unique resource. */ |
private $uid = NULL; |
|
/** True si le type d'api est CGI / FastCGI, false si on a un module Apache... ou autre ? */ |
public static $cgi; |
|
/** |
* Constructor. Parses the configuration file "JRest.ini", grabs any request data sent, records the HTTP |
* request method used and parses the request URL to find out the requested resource |
63,6 → 66,10 |
} |
} |
|
// détection du type d'API : CGI ou module Apache - le CGI ne permet pas |
// d'utiliser l'authentification HTTP Basic :-( |
self::$cgi = substr(php_sapi_name(), 0, 3) == 'cgi'; |
|
$this->method = $_SERVER['REQUEST_METHOD']; |
} else { |
trigger_error('I require the server variables REQUEST_URI, REQUEST_METHOD and QUERY_STRING to work.', E_USER_ERROR); |
261,10 → 268,12 |
* Send a HTTP 401 response header. |
*/ |
private function unauthorized($realm = 'JRest') { |
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
header('WWW-Authenticate: Basic realm="'.$realm.'"'); |
if (self::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux) |
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
header('WWW-Authenticate: Basic realm="'.$realm.'"'); |
} |
header('HTTP/1.0 401 Unauthorized'); |
} |
header('HTTP/1.0 401 Unauthorized'); |
} |
|
/** |