• 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)
  • why are you trying to read if the wp header was spat out?

    If its not then your site is going to be broken.

    Seems like a lot of work for nothing however….

    Look up the way you Enqueue javascript and verify if a previous version is enqueued that might work for your verification

    Thread Starter tommytx

    (@tommytx)

    I just need a way to read the header info to see if the loaded page was a 404 or not… and I need this info before it goes thru the WP 404 verification…. that is too late to take the action that i need to take…. Isn’t there some way to capture the header when a page loads…

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.