Last active
March 28, 2024 12:58
-
-
Save lrtrln/1a0d96e317c3322a53eacf569fb01612 to your computer and use it in GitHub Desktop.
HTTP header save-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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