Is there a way to getheader() in WP for loaded file.
-
I can use getheader() to grab the header of a web page, but is there a way to get the header of the file that was just loaded or being loaded… Primarily what I want to detect is when it went for the file to load did it come back as 404 or 200… so bottom line is there a way to read the header that the webpage saw when it requested a page?
I tried this code in the index. php file but apparently you cannot ask for the header from a site that is downloading… guess you would have to wait for the page to download to free up the server before you could ask it for the header.. The below code is in my index.php file for the blog.
$uri = $_SERVER["REQUEST_URI"]; // echo "URI = $uri<br>"; if (strpos($uri, "mls-")) { $url = "http://mydomain.com" . $uri; $dat = get_headers($url); // echo "$dat[0]<br>"; $str = explode(' ', $dat[0]); // echo "Error = $str[1]<br>"; if ($str[1]=="404") { $str = explode("_ca_", $uri); $zipcode = $str[1]; $out = "http://mydomain.com/idx/zip/$zipcode/"; // echo "<h3>Out = $out</h3><br>"; // exit; header("HTTP/1.1 301 Moved Permanently"); header("Location: $out"); exit; } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Is there a way to getheader() in WP for loaded file.’ is closed to new replies.