PHP Classes

File: examples/example3.php

Recommend this page to a friend!
  Classes of Tom Postma  >  PHP Content Security Policy generator  >  examples/example3.php  >  Download  
File: examples/example3.php
Role: Example script
Content type: text/plain
Description: Example: how to allow to use ajax requests.
Class: PHP Content Security Policy generator
Generate CSP headers to prevent security attacks
Author: By
Last change: Update examples, in examples 2 and 6 the resources are only loaded over https.

Signed-off-by: Tom <>
Date: 3 years ago
Size: 893 bytes


Class file image Download

// Allow use of AJAX requests to same origin.

// Set the headers, always call this method before any content output.
if (!empty(
filter_input(INPUT_GET, 'getresponse'))) {
header('X-Content-Type-Options: nosniff');
header('Content-type: text/xml; charset=utf-8');
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'."\r\n";
} else {
?><!DOCTYPE html>
        <meta charset="UTF-8">
        <title>example3 - allow ajax requests to same orgin</title>
        <div id="result"><noscript>JavaScript not enabled.</noscript></div>
        <script type="application/javascript" src="./example3.js"></script>

For more information send a message to info at phpclasses dot org.