php - Error getting array value by key -


this strange one.

i'm making request following code.

$opts = array(   'http'=>array(     'method'=>"get",     'header'=>"accept-language: en\r\n" .               "bearer: 5ae3lc//bq+k+m2m+tugxw4k4k8=:i3khkxstnxs9fnag/igwpnhyfbo=\r\n" .               "cookie: foo=bar\r\n"   ) ); $context = stream_context_create($opts); $file = fopen($csvfile, 'r', false, $context); 

in script receiving request have this:

$headers = getallheaders(); var_dump($headers['bearer']); // undefined index: bearer $headers = json_decode(json_encode($headers), true); var_dump($headers['bearer']); //this 1 works. 

but var_dump of $headers array looks same before or after encode , decode.

//first var_dump     array(4) {       ["host"]=>       string(19) "" //removed       ["accept-language"]=>       string(2) "en"       ["bearer"]=>       string(57) "5ae3lc//bq+k+m2m+tugxw4k4k8=:i3khkxstnxs9fnag/igwpnhyfbo="       ["cookie"]=>       string(7) "foo=bar"     } //second var_dump, after decode/encode     array(4) {       ["host"]=>       string(19) "" //removed       ["accept-language"]=>       string(2) "en"       ["bearer"]=>       string(57) "5ae3lc//bq+k+m2m+tugxw4k4k8=:i3khkxstnxs9fnag/igwpnhyfbo="       ["cookie"]=>       string(7) "foo=bar"     } 

the "bearer" key 1 can't access beginning. can others without problem.

var_dump array_keys of $headers

array(8) {   [0]=>   string(4) "host"   [1]=>   string(10) "connection"   [2]=>   string(10) "user-agent"   [3]=>   string(6) "bearer"   [4]=>   string(6) "accept"   [5]=>   string(15) "accept-encoding"   [6]=>   string(15) "accept-language"   [7]=>   string(6) "cookie" } 

why happen?

/, =, , : separator characters in http headers. try encoding value bearer when defining $opts

$opts = array(     'http'=>array(         'method'=>"get",         'header'=>"accept-language: en\r\n" .                   "bearer: " . urlencode('5ae3lc//bq+k+m2m+tugxw4k4k8=:i3khkxstnxs9fnag/igwpnhyfbo=') . "\r\n" .                   "cookie: foo=bar\r\n"     ) ); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -