Ho un problema davvero frustrante in cui non riesco a recuperare nessuna delle intestazioni. Ecco il mio codice:PHP Weird Undefined index error
$headers = getallheaders();
echo($headers["SystemTime"]); //Doesnt work
$keys = array_keys($headers);
echo($headers[$keys[4]]); //Doesnt work
Entrambe le righe generano l'errore "Indice non definito: SystemTime".
Non posso per la vita di me capire perché non riesco a ottenere il valore. Se vado print_r($headers);
ottengo questo
Array
(
[Content-Type] => application/x-www-form-urlencoded
[Content-Length] => 0
[Host] => localhost
[Referer] =>
[SystemTime] => 2012-06-26+09%3a20%3a27
)
var_dump di $ headers
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"
}
var_dump di $ chiavi
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";
}
tornato:
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:
Im bloccato e ho seriamente non riesco a capire cosa sia andare storto. Dovrebbe funzionare.
PS. So che l'intestazione SystemTime non è standard. Fornisco questo dal mio http_request.
Quale versione di PHP stai utilizzando? – drew010
Usa 'var_dump()' per vedere se le stringhe (chiavi) sono ciò che ti aspetti (ad esempio byte null o unicode ws). Anche 'SystemTime' non è un'intestazione standard. Chi l'ha aggiunto? E per "qualsiasi intestazione" intendi che hai provato quelli ordinari? – mario
Versione PHP 5.2.17 –