Check if Sec-GPC value exists in HTTP request header in WordPress
P粉930534280
P粉930534280 2023-08-31 13:34:53
0
1
378
<p>如何检测 HTTP 请求标头中是否存在“Sec-GPC:1”?</p> <pre class="brush:php;toolbar:false;"><?PHP function detect_gpc_signal() { if (isset($_GET['Sec-Gpc'])) { echo 'GPC signal detected in GET data'; } elseif (isset($_POST['Sec-Gpc'])) { echo 'GPC signal detected in POST data'; } elseif (isset($_COOKIE['Sec-Gpc'])) { echo 'GPC signal detected in COOKIE data'; } elseif (isset($_SERVER['Sec-Gpc'])) { echo 'GPC signal detected in SERVER data'; } else { echo 'No GPC signal detected'; } } add_action('wp_footer', 'detect_gpc_signal'); ?></pre></p>
P粉930534280
P粉930534280

reply all(1)
P粉311464935

Thanks for suggesting getallheaders(). With your help I found two ways, with and without Javascript.

/* Add GPC Banner to WP Header */
function display_gpc_signal_banner() {
echo '
Global Privacy Signal Detected
'; } add_action('wp_head', 'display_gpc_signal_banner'); // Detect GPC Signal with Javascript function detect_gpc_signal_js() { ?>

renew

The original function will work when HTTP_ is added to the value.

if (isset($_GET['HTTP_SEC_GPC'])) {
  echo 'GPC signal detected in GET data';
  } elseif (isset($_POST['HTTP_SEC_GPC'])) {
  echo 'GPC signal detected in POST data';
  } elseif (isset($_COOKIE['HTTP_SEC_GPC'])) {
  echo 'GPC signal detected in COOKIE data';
  } elseif (isset($_SERVER['HTTP_SEC_GPC'])) {
  echo 'GPC signal detected in SERVER data';
  } else {
   echo 'No GPC signal detected';
  }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!