Skip to content

Instantly share code, notes, and snippets.

@lrtrln
Last active March 28, 2024 12:58
Show Gist options
  • Save lrtrln/1a0d96e317c3322a53eacf569fb01612 to your computer and use it in GitHub Desktop.
Save lrtrln/1a0d96e317c3322a53eacf569fb01612 to your computer and use it in GitHub Desktop.
HTTP header save-data
<?php
function getHttpRequestHeaders()
{
$headers = [];
foreach ($_SERVER as $key => $value) {
if (substr($key, 0, 5) === 'HTTP_') {
$headerKey = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
$headers[$headerKey] = $value;
}
}
return $headers;
}
function dataSavingMode()
{
$headers = getHttpRequestHeaders();
if (isset($headers['Save-Data']) && $headers['Save-Data'] === 'on') {
return true;
} else {
return false;
}
}
?>
use
<?php if(dataSavingMode()): ?>
<p>DATA</p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment