ヘッダーを取得できないという非常にイライラする問題があります。これが私のコードです:
$headers = getallheaders();
echo($headers["SystemTime"]); //Doesnt work
$keys = array_keys($headers);
echo($headers[$keys[4]]); //Doesnt work
両方の行で、「未定義のインデックス: SystemTime」というエラーが生成されます。
私は一生、価値を得ることができない理由を理解できません。私が行くなら、私はprint_r($headers);
これを手に入れます
Array
(
[Content-Type] => application/x-www-form-urlencoded
[Content-Length] => 0
[Host] => localhost
[Referer] =>
[SystemTime] => 2012-06-26+09%3a20%3a27
)
$headers の var_dump
array(5) {
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Content-Length"]=>
string(1) "0"
["Host"]=>
string(9) "localhost"
["Referer"]=>
string(0) ""
["SystemTime"]=>
string(23) "2012-06-26+10%3a10%3a08"
}
$keys の var_dump
array(5) {
[0]=>
string(12) "Content-Type"
[1]=>
string(14) "Content-Length"
[2]=>
string(4) "Host"
[3]=>
string(7) "Referer"
[4]=>
string(10) "SystemTime"
}
foreach ($headers as $name => $value) {
echo "$name: $value. From Array: {$headers[$name]}\n";
}
戻ってきた:
Connection: Keep-Alive. From Array: Keep-Alive
Content-Type: application/x-www-form-urlencoded. From Array: application/x-www-form-urlencoded
Content-Length: 0. From Array: 0
Host: localhost. From Array: localhost
Referer: . From Array:
Notice: Undefined index: SystemTime in /clientdata/apache-www/a/d/[XXXXXX].com/www/admin/request/GetPCLicence.php on line 22
SystemTime: 2012-06-26+10%3a10%3a08. From Array:
私は立ち往生しており、何が問題なのか真剣に理解できません。それはうまくいくはずです。
PS。SystemTime ヘッダーが非標準であることはわかっています。http_request から提供します。