-2

I am using get_headers to verify the validity of a URL.

https://central.bac-lac.gc.ca/.item/?app=Census1921&op=img&id=e002943819

If I enter this URL into my browser it works. But if I wish to test the URL BEFORE stuffing it into a tag by passing it to get_headers it fails.

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /home/jamescobban/public_html/DisplayImage.php on line 186

Warning: get_headers(): Failed to enable crypto in /home/jamescobban/public_html/DisplayImage.php on line 186

Warning: get_headers(https://central.bac-lac.gc.ca/.item/?app=Census1921&op=img&id=e002943819): failed to open stream: operation failed in /home/jamescobban/public_html/DisplayImage.php on line 186

So my code issues an error message instead of stuffing the URL into the tag.

See this at https://www.jamescobban.net/DisplayImage.php?src=https%3A%2F%2Fcentral.bac-lac.gc.ca%2F.item%2F%3Fapp%3DCensus1921%26op%3Dimg%26id%3De002943819&buttonname=imageButton&lang=en

Contrast this with https://www.jamescobban.net/DisplayImage.php?src=https%3A%2F%2Fdata2.collectionscanada.ca%2F1911%2Fjpg%2Fe001984006.jpg&buttonname=imageButton&lang=en which is administered by the same department but on a different server. Since the response is nothing but a JPEG I have asked them why they have added the complexity of running a script but they are the GOVERNMENT and do not have to answer to mere taxpayers. Fortunately for the moment they have not removed the old servers which simply stored the images, but that access mode is not available for the most recently released census. As you can see the only purpose of my script is to add a wrapper around the JPEG to permit the user to perform some operations on the image.

I suspect the problem is that this GOVERNMENT web-site is using an expired certificate. I reported that I had detected that problem to the department several months ago but they are using the excuse of COVID to sit on their backsides even though obviously their website is more important than ever in these days when we cannot walk into their office!

How can I convince get_headers to ignore the bad certificate the same way that the browsers do? After all it is not that I distrust that a domain ending in ".gc.ca" is legitimately provided by the government, but it is still desirable for privacy reasons to encrypt my exchanges with any government agency.

The suggestion to turn off security checking is unacceptable. I just want get_headers to tell me whether the URL can be used in the tag so that I do not get the default error message from the browser.

If you want to see the code that is calling get_header go to https://github.com/jcobban/Genealogy/blob/master/DisplayImage.php

  • The server has a broken setup, see [this SSLLabs report](https://www.ssllabs.com/ssltest/analyze.html?d=central.bac-lac.gc.ca) and look for "chain is incomplete". That's why it fails. And don't expect others to dig through some large code in order to find out what you are doing - create a minimal example instead. – Steffen Ullrich Jan 17 '21 at 22:48
  • Thank you for your response. However there is no way that I can control what the administrators of another site do, or don't do. This is a government server that I am simply trying to define links to from my site. As I said I already knew that the certificate was broken. But no browser, not even Firefox, complains about this poor quality certificate, not even in a warning. I need a way to verify that an href will work before stuffing it into a tag. I need to be able to work with servers that are broken and that I CANNOT FIX. – James Cobban Jan 17 '21 at 23:01

1 Answers1

0

I got this to work by supplying a context:

        $context    = stream_context_create(['ssl' => [
                                                'verify_peer' => false,
                                                'verify_peer_name' => false,
                                            ]]);
        $headers                = get_headers($src,0,$context);