SUPERCAT.DEV

Benvenut* sul mio blog

PHP

Controllo headers

19-11-2024

Visualizza gli header

<?php

function my_is_404($url) {
    if(!filter_var($url, FILTER_VALIDATE_URL)) {
        return true;
    }
    $headers = get_headers($url);
    var_dump($headers);
    return strstr($headers[0], '404') !== false;
}

var_dump(my_is_404('https://www.google.com'));

Risultato

array(15) {
  [0]=>
  string(15) "HTTP/1.0 200 OK"
  [1]=>
  string(35) "Date: Tue, 19 Nov 2024 14:16:34 GMT"
  [2]=>
  string(11) "Expires: -1"
  [3]=>
  string(33) "Cache-Control: private, max-age=0"
  [4]=>
  string(43) "Content-Type: text/html; charset=ISO-8859-1"
  [5]=>
  string(243) "Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-3lHgXYz2Hh1yrsZIXCpJzw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp"
  [6]=>
  string(38) "Accept-CH: Sec-CH-Prefers-Color-Scheme"
  [7]=>
  string(67) "P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info.""
  [8]=>
  string(11) "Server: gws"
  [9]=>
  string(19) "X-XSS-Protection: 0"
  [10]=>
  string(27) "X-Frame-Options: SAMEORIGIN"
  [11]=>
  string(173) "Set-Cookie: AEC=AZ6Zc-VM3ULgZKz5Zg-oXBjRwFzKwK5mo2pjk_YI4BmIAADgyauJ_ncjYA; expires=Sun, 18-May-2025 14:16:34 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax"
  [12]=>
  string(299) "Set-Cookie: NID=519=B41MsoJ0WRifZbJh9G_yFsibazt_SnFOK6j0Vr_iBQoJFDB_oAsBxtenbSfGTPcR9oot9FQD7MV5QUS16zOWeqZlHVh9U6cVAU45WoAN5PrnWLszDi4F1pl6o4h9FaaUc7GFbUoPXz1lNdQrGAEzvR1LYG6YdZ67Zo_Phd38NtVNXiJRD9gPah0RHrnkuHWYsgSw3Ikt6g; expires=Wed, 21-May-2025 14:16:34 GMT; path=/; domain=.google.com; HttpOnly"
  [13]=>
  string(19) "Accept-Ranges: none"
  [14]=>
  string(21) "Vary: Accept-Encoding"
}
bool(false)