PHP Classes

File: examples/example8.php

Recommend this page to a friend!
  Classes of Tom Postma   PHP Content Security Policy generator   examples/example8.php   Download  
File: examples/example8.php
Role: Example script
Content type: text/plain
Description: Example: how to add the upgrade-insecure-requests directive (for easy https ready)
Class: PHP Content Security Policy generator
Generate CSP headers to prevent security attacks
Author: By
Last change:
Date: 6 years ago
Size: 1,266 bytes


Class file image Download
// Automatically rewrite http:// url's to https:// url's when using https(HTTP over TLS/SSL).

// Set the headers, always call this method before any content output.
// Start content output.
?><!DOCTYPE html>
        <meta charset="UTF-8">
        <title>example8 - Upgrade-insecure-requests</title>
= false;
if (isset(
    if (
$_SERVER['HTTPS'] == 'on') {
$ishttps = true;

if (
$ishttps) { ?>
Image source url starts with http:// protocol handler but it's rewriten to the https:// protocol handler to load the image with https because of the <code>upgrade-insecure-requests</code> directive in the Content Security Policy header.<br />
        <img src="" alt="Image with http url will be loaded as https url.">
<?php } else { ?>
<b>To test the Content Security Policy <code>Upgrade-insecure-requests</code> directive it's required to visit this page over https.</b>
<?php } ?>