3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hashAlgo = 'sha384'; //$hashAlgo = 'sha256'; $maxHeaderLength = 2048; // $maxHeaderLength = 3072; // Do not change after here $baseCsp = "default-src 'self'; report-uri https://www.my-super-domain.com/_contao/csp/report/51; style-src 'self' 'unsafe-hashes' 'nonce-H0Sss0Ol1d/r/rgWp4sRk3IT'; script-src 'self' 'unsafe-hashes' 'nonce-H0Sss0Ol1d/r/rgWp4sRk3IT'"; // + 3 for wrapping '' and space $lengthOfOneHash = strlen($hashAlgo . '-' . base64_encode(hash($hashAlgo, 'text-decoration: underline'))) + 3; $count = 0; $total = strlen($baseCsp); while (true) { $total += $lengthOfOneHash; if ($total > $maxHeaderLength) { echo 'Could fit ' . $count . ' hashes in the CSP header.'; break; } $count++; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Could fit 13 hashes in the CSP header.

preferences:
79.47 ms | 402 KiB | 61 Q