我正在使用Rest_controller处理codeigniter基本身份验证。目前我遇到的问题是从我的$_SERVER
数组对象中获取下面列表中的任何人。
PHP_AUTH_USER
PHP_AUTH_PW
HTTP_AUTHORIZATION
HTTP_AUTHENTICATION
根据我的研究,问题是因为我服务器上的Server API。此服务器的服务器API使用CGI / FastCGI。
我甚至尝试将所有这些添加到我的.htaccess
,但它们都不适用于我。
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
CGIPassAuth on
Header set Access-Control-Allow-Headers: "Authorization"
下面的数组是当我尝试从邮递员调用我的api时从$_SERVER
得到的数据。
array(52) {
["PATH"]=>
string(28) "/usr/local/bin:/usr/bin:/bin"
["TZ"]=>
string(16) "America/New_York"
["REDIRECT_HANDLER"]=>
string(28) "application/x-httpd-ea-php56"
["REDIRECT_STATUS"]=>
string(3) "200"
["UNIQUE_ID"]=>
string(27) "Wgu-pu3SJZU707d76yB41AAAAAE"
["SCRIPT_URL"]=>
string(24) "/index.php/test_api/test"
["SCRIPT_URI"]=>
string(49) "https://www.river-app.com/index.php/test_api/test"
["HTTPS"]=>
string(2) "on"
["SSL_TLS_SNI"]=>
string(17) "www.river-app.com"
["HTTP_HOST"]=>
string(17) "www.river-app.com"
["HTTP_CONNECTION"]=>
string(10) "keep-alive"
["CONTENT_LENGTH"]=>
string(1) "0"
["HTTP_CACHE_CONTROL"]=>
string(8) "no-cache"
["HTTP_ORIGIN"]=>
string(51) "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop"
["HTTP_USER_AGENT"]=>
string(121) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
["HTTP_POSTMAN_TOKEN"]=>
string(36) "12be9c43-7d88-3244-b407-ff0a160434ce"
["HTTP_ACCEPT"]=>
string(3) "*/*"
["HTTP_ACCEPT_ENCODING"]=>
string(17) "gzip, deflate, br"
["HTTP_ACCEPT_LANGUAGE"]=>
string(38) "en-US,en;q=0.8,zh-CN;q=0.6,zh-TW;q=0.4"
["HTTP_COOKIE"]=>
string(43) "ci_session=ne4ip07sqkrree86dgmjfackgbn4f4bk"
["HTTP_X_HTTPS"]=>
string(1) "1"
["SERVER_SIGNATURE"]=>
string(0) ""
["SERVER_SOFTWARE"]=>
string(6) "Apache"
["SERVER_NAME"]=>
string(17) "www.river-app.com"
["SERVER_ADDR"]=>
string(14) "67.225.226.183"
["SERVER_PORT"]=>
string(3) "443"
["REMOTE_ADDR"]=>
string(15) "118.200.235.133"
["DOCUMENT_ROOT"]=>
string(26) "/home/riverapp/public_html"
["REQUEST_SCHEME"]=>
string(5) "https"
["CONTEXT_PREFIX"]=>
string(8) "/cgi-sys"
["CONTEXT_DOCUMENT_ROOT"]=>
string(26) "/usr/local/cpanel/cgi-sys/"
["SERVER_ADMIN"]=>
string(23) "webmaster@river-app.com"
["SCRIPT_FILENAME"]=>
string(36) "/home/riverapp/public_html/index.php"
["REMOTE_PORT"]=>
string(5) "60875"
["REDIRECT_URL"]=>
string(24) "/index.php/test_api/test"
["GATEWAY_INTERFACE"]=>
string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=>
string(8) "HTTP/1.1"
["REQUEST_METHOD"]=>
string(4) "POST"
["QUERY_STRING"]=>
string(0) ""
["REQUEST_URI"]=>
string(24) "/index.php/test_api/test"
["SCRIPT_NAME"]=>
string(10) "/index.php"
["PATH_INFO"]=>
string(14) "/test_api/test"
["PATH_TRANSLATED"]=>
string(40) "/home/riverapp/public_html/test_api/test"
["ORIG_PATH_INFO"]=>
string(24) "/index.php/test_api/test"
["ORIG_SCRIPT_NAME"]=>
string(17) "/cgi-sys/ea-php56"
["ORIG_SCRIPT_FILENAME"]=>
string(34) "/usr/local/cpanel/cgi-sys/ea-php56"
["ORIG_PATH_TRANSLATED"]=>
string(50) "/home/riverapp/public_html/index.php/test_api/test"
["PHP_SELF"]=>
string(24) "/index.php/test_api/test"
["REQUEST_TIME_FLOAT"]=>
float(1510719398.04)
["REQUEST_TIME"]=>
int(1510719398)
["argv"]=>
array(0) {
}
["argc"]=>
int(0)
}
导致此问题的原因可能是什么。
答案 0 :(得分:0)
尝试将此行添加到控制器顶部
header('Content-Type: application/json');