PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Michael A. Peters   CSP Filter   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: CSP Filter
Filter HTML based on Content Security Policy
Author: By
Last change: Example updated
Date: 14 years ago
Size: 1,007 bytes


Class file image Download
$htmlfile = "README.html";
$buffer = file_get_contents($htmlfile);

$domdoc = new DOMDocument("1.0","utf-8");
$domdoc->preserveWhiteSpace = false;
$domdoc->formatOutput = true;

$filter = new cspfilter($domdoc);
$filter->csp['allow'] = 'none';
$filter->csp['img-src'] = '';


// ignore this part of the source - I'm modifying the README.html
// content to insert actual example of policy violation report
$report = $filter->displayViolationReport();
$reportNode = $domdoc->createElement("pre",$report);
$elements = $domdoc->getElementsByTagName("pre");
foreach (
$elements as $element) {
   if (
$element->hasAttribute('id')) {
$id = $element->getAttribute('id');
      if (
$id == 'treport') {
// end ignore

print $domdoc->saveHTML();