<?php
    
if (isset($_GET['source'])) {
        
highlight_file(__FILE__);
        exit;
    }

    if (!empty(
$_GET['csp'])) {
        
header('Content-Security-Policy: ' $_GET['csp']);
    }

    if (isset(
$_GET['framed'])) {
        die(
'I am a frame!');
    }

    echo 
'<form><input name=csp size=80 value="' htmlspecialchars($_GET['csp']) . '"><br><input type=submit value=Set></form>';

    if (
strpos($_SERVER['SERVER_NAME'], 'lgms.nl') === false) {
        
$otherdomain 'lgms.nl';
    }
    else {
        
$otherdomain 'lucgommans.nl';
    }
?>
<a href='?source'>View source</a> | <a href='?csp='>Clear CSP</a> | <a href="?csp=default-src+'self'">Set default-src 'self'</a> | <a href="?csp=frame-ancestors+'self'">Set frame-ancestors 'self'</a><br>
<br>

<div id=x></div>
<script>
    document.getElementById('x').innerHTML = '- Inline javascript works';
</script>
<br>
- Framing self: <iframe src='csp-test.php?framed&amp;csp=<?php echo htmlspecialchars(urlencode($_GET['csp'])); ?>' height=60>No framing</iframe><br>
- Framing cross-origin: <iframe src='https://<?php echo $otherdomain?>/p/csp-test.php?framed&amp;csp=<?php echo htmlspecialchars(urlencode($_GET['csp'])); ?>' height=60>No framing</iframe><br>