2017-10-07 91 views
-1

夥計。我正在建造一個加密硬幣挖掘池,原來的游泳池基於Node.JS.哪個Node.JS沒有達到採礦池的快節奏。所以我建立了一個運行在NGINX和PHP中的池。礦工如何工作,它與Pool API交互。礦工在頭文件中有一些重要的信息,比如礦工類型,版本,容量等等。有沒有辦法用PHP來獲取頭文件,如果不能用JavaScript來完成的話。謝謝。 :)如何使用PHP或JavaScript獲取客戶端響應頭?

使用的是Node.js我所用:req.headers

這是我在PHP中曾嘗試:

$_SERVER["USER"] = www-data 
$_SERVER["HOME"] = /var/www 
$_SERVER["HTTP_HOST"] = 10.10.31.95 
$_SERVER["HTTP_USER_AGENT"] = Jetty/9.4.2.v20170220 
$_SERVER["HTTP_ACCEPT_ENCODING"] = gzip 
$_SERVER["REDIRECT_STATUS"] = 200 
$_SERVER["SERVER_NAME"] = _ 
$_SERVER["SERVER_PORT"] = 80 
$_SERVER["SERVER_ADDR"] = 10.10.31.95 
$_SERVER["REMOTE_PORT"] = 57488 
$_SERVER["REMOTE_ADDR"] = 10.10.30.0 
$_SERVER["SERVER_SOFTWARE"] = nginx/1.10.3 
$_SERVER["GATEWAY_INTERFACE"] = CGI/1.1 
$_SERVER["REQUEST_SCHEME"] = http 
$_SERVER["SERVER_PROTOCOL"] = HTTP/1.1 
$_SERVER["DOCUMENT_ROOT"] = /var/www/html 
$_SERVER["DOCUMENT_URI"] = /burst.php 
$_SERVER["REQUEST_URI"] = /burst?requestType=getMiningInfo 
$_SERVER["SCRIPT_NAME"] = /burst.php 
$_SERVER["CONTENT_LENGTH"] = 
$_SERVER["CONTENT_TYPE"] = 
$_SERVER["REQUEST_METHOD"] = GET 
$_SERVER["QUERY_STRING"] = requestType=getMiningInfo 
$_SERVER["SCRIPT_FILENAME"] = /var/www/html/burst.php 
$_SERVER["PATH_INFO"] = 
$_SERVER["FCGI_ROLE"] = RESPONDER 
$_SERVER["PHP_SELF"] = 
$_SERVER["REQUEST_TIME_FLOAT"] = 1507362021.8898 
$_SERVER["REQUEST_TIME"] = 1507362021 
+0

任何標題,特別是你需要?它應該位於相應的'$ _SERVER [HTTP_HEADER_NAME]'字段中 – apokryfos

+0

您可以在$ _SERVER [「HTTP_HOST」] = 10.10.31.95', '$ _SERVER [「HTTP_USER_AGENT」] = Jetty/9.4.2.v20170220', '$ _SERVER [「HTTP_ACCEPT_ENCODING」] = gzip' –

+0

echo $ _SERVER [「HTTP_HEADER_NAME」];注意:第7行的/var/www/html/index.php中的未定義索引:HTTP_HEADER_NAME –

回答

0

這工作

function get_contents() { 
    file_get_contents("http://example.com"); 
    var_dump($http_response_header); 
} 
get_contents(); 
var_dump($http_response_header); 

出放。

array(13) { 
[0]=> string(15) "HTTP/1.0 200 OK" 
[1]=> string(20) "Accept-Ranges: bytes" 
[2]=> string(29) "Cache-Control: max-age=604800" 
[3]=> string(23) "Content-Type: text/html" 
[4]=> string(35) "Date: Sat, 07 Oct 2017 23:51:45 GMT" 
[5]=> string(22) "Etag: "359670651+gzip"" 
[6]=> string(38) "Expires: Sat, 14 Oct 2017 23:51:45 GMT" 
[7]=> string(44) "Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT" 
[8]=> string(22) "Server: ECS (lga/1386)" 
[9]=> string(21) "Vary: Accept-Encoding" 
[10]=> string(12) "X-Cache: HIT" 
[11]=> string(20) "Content-Length: 1270" 
[12]=> string(17) "Connection: close" 
} 
相關問題