Search code examples
phpget-headers

php get_headers location


how to use php get_headers only get location part?

var_dump(get_headers('http://www.google.com',1));

This return:

array(12) { [0]=> string(18) "HTTP/1.0 302 Found" ["Location"]=> string(21) "http://www.google.it/" ... }

Then I use

echo (get_headers('http://www.google.com',1)["Location"];

error: Parse error: syntax error, unexpected '[' in this echo line


Solution

  • $headers = get_headers('http://www.google.com',1);
    echo $headers["Location"];