Conditions | 5 |
Paths | 9 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | static public function contentSecurityPolicy($policy) |
||
18 | { |
||
19 | foreach ($policy as $key => $values) { |
||
20 | // if the value is not an array, we also accept newline terminated strings |
||
21 | if (!is_array($values)) $values = explode("\n", $values); |
||
22 | $values = array_map('trim', $values); |
||
23 | $values = array_unique($values); |
||
24 | $values = array_filter($values); |
||
25 | $policy[$key] = $values; |
||
26 | } |
||
27 | |||
28 | $cspheader = 'Content-Security-Policy:'; |
||
29 | foreach ($policy as $key => $values) { |
||
30 | if ($values) { |
||
31 | $cspheader .= " $key " . join(' ', $values) . ';'; |
||
32 | } else { |
||
33 | $cspheader .= " $key;"; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | header($cspheader); |
||
38 | } |
||
39 | } |
||
40 |