1

I got error from my Apache log:

php warning: illegal string offset ‘name’ in GetUrl.php on line 855

Here is the page code:

function find_header_by_name($header_name) {
    if (!$this - > headers_received) {
        $this - > GetUri - > errors[] = “Error looking up header: headers have not been received yet”;
        return false;
    }

    $Response = false;
    foreach($this - > headers as $header) {
        if (!strcasecmp($header[‘name’], $header_name))
            $Response[] = $header[‘value’];
    }
    return $Response;
}

The error code is this part:

foreach($this - > headers as $header) {
    if (!strcasecmp($header[‘name’], $header_name))
        $Response[] = $header[‘value’];
}
return $Response;

How to fix it? I can’t find it, please help

Jesse
  • 2,790
  • 1
  • 20
  • 36
Randy
  • 21
  • 3

1 Answers1

1

You can

print_r($this->headers);

or

var_dump($this->headers);

to check it has results or not.

if there is not have any results,there will throw the error that you seen.

p.s:I'm a Chinese,this is my first answer in stackoverflow,I hope you can remember what i said ;)

X Ray
  • 34
  • 1
  • Welcome to the site. You do not have to specify if you are Chinese. :) – Jesse Sep 28 '15 at 04:11
  • Keep in mind, that answers are for specific answers, as to where you have found the problem and are providing the specific answer to the problem. For answers such as recommendations on how the problem can be found, a comment is best used . This is right below the post as a link labeled "add a comment" – Jesse Sep 28 '15 at 04:12
  • when i use print_r($this->headers); as you said, i got result like this [7] => Array ( [name] => Content-Length [value] => 261 ) [8] => Array ( [name] => X-XSS-Protection [value] => 1; mode=block ) [9] => Array ( [name] => X-Frame-Options [value] => SAMEORIGIN ) – Randy Sep 28 '15 at 04:35
  • when var_dump($this->headers); i got this blew: [7]=> array(2) { ["name"]=> string(14) "Content-Length" ["value"]=> string(3) "261" } [8]=> array(2) { ["name"]=> string(16) "X-XSS-Protection" ["value"]=> string(13) "1; mode=block" } [9]=> array(2) { ["name"]=> string(15) "X-Frame-Options" ["value"]=> string(10) "SAMEORIGIN" } – Randy Sep 28 '15 at 04:38
  • I can't type 'enter' in this textarea!!! This result is a two-dimension array,the key 'name' is belong the key '7'. So you can modify you code like this " if (!strcasecmp($header[7][‘name’], $header_name)) $Response[] = $header[7][‘value’];" – X Ray Sep 28 '15 at 04:44
  • No, can't do this, this is just a part of my print_r($this->headers); result, i have hundreds of name keys on my result contents, each time how many name keys on my result it is not sure,maybe this time 15, and next time 60 – Randy Sep 28 '15 at 04:52
  • oh,sorry,I thought you just want get one result. You can use the array's 'key' to test it. try this code: foreach($this -> headers as $k=>$v) { if (!strcasecmp($this->headers[$k]['name'], $header_name)) $Response[] = $this->headers[$k]['value']; } – X Ray Sep 28 '15 at 05:18