Quantcast
Channel: ruk.ca - Peter Rukavina's Weblog
Viewing all articles
Browse latest Browse all 4349

Going Secure. Or All the Images

$
0
0

I’m in the midst of a plan to migrate this site to a secure server – https instead of http– and as part of that plan I need to ferret out all the embedded images that are called from non-secure hosts, so as to avoid mixed-content issues

There are 6,953 pages that make up this site — all the blog posts and “about” pages taken together. This bit of PHP code extracts all URLs of all of the images embedded in the body of all of those pages by directly querying the Drupal node table:

$query = "SELECT entity_id,body_value from field_data_body";
$result = $db7->query($query);
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
  $doc = new DOMDocument();
  @$doc->loadHTML($row['body_value']);
  $imageTags = $doc->getElementsByTagName('img');
  foreach($imageTags as $tag) {
      print $tag->getAttribute('src') . "\n";
  }
}

That script identifies 4,325 images in total, ranging from the good old:

/1by1.gif

to images on hosts like Flickr:

https://farm2.staticflickr.com/1603/23977645632_c8b864d187_c.jpg

Some of these images – like 1by1.gif – are 404, and I’ll need to do some manual corrections to the HTML for those mosts; others, like that Flickr example, are perfectly fine to serve on the new secure site as they’re already hosted on a secure server (note the https in the Flickr URL). But there are a lot of images that are served from non-secure hosts that I control, like:

http://media.ruk.ca/images/email-keyboard-20160124-120123.png

For images like that, I’ll need to change the URL to either:

//media.ruk.ca/images/email-keyboard-20160124-120123.png

or

https://media.ruk.ca/images/email-keyboard-20160124-120123.png

Of the 4,325 images, 3,587 (83%) are from non-secure hosts, 244 (6%) are from secure hosts, and 494 are relative embeds with no host indicated. It breaks down like this:

  • Flickr (non-secure): 1678 images
  • Flickr (secure): 233 images
  • ruk.ca (non-secure): 1011 images
  • media.ruk.ca (non-secure): 632 images
  • Third-party hosts (non-secure): 255 images
  • Relative embeds without host: 494 images

My plan is to move all of these images to a secure server under my control and then to rewrite the embedded URLs to point there.

As an aside, one of the things I found out while I was under the hooking mucking about with the blog was that I’ve written 1,439,497 words here since 1999. That’s Catch-22 times 8 or Fahrenheit 451 times 31. If only mine were such quality words as those.


Viewing all articles
Browse latest Browse all 4349

Trending Articles