I want to find the final redirected status codes for a webpages in a certain site. After given expiry date this site deletes these pages and redirects you to its home page with 404 status code.
Let's say one of the pages I want to go is http://example.com/my-page and this page does not exist anymore. So it will redirect me to http://example.com/. I checked with chrome developer tools and it sends a 404 status code.
Now here is the problem. I want to check whether this page is a 404 or not. I have following PHP function.
    function findStatus($url)
    {
        $handle = curl_init($url);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
        /* Check for 404 (file not found). */
        $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
        curl_close($handle);
        if ($httpCode == 404) {
            return true;
        } else {
            return false;
        }
    }
When I check the relevant page with above function I get 302 for permanent redirection. I guess this function gets the status code before redirection.
This answer describes how to get the URL, but not status code. How do I get status code after page's redirection complete?