You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress中如何检测HTTP请求头是否存在Sec-GPC:1?

如何检测HTTP请求头中是否存在「Sec-GPC:1」?

要检测HTTP请求头里的Sec-GPC:1,可以通过PHP的几个全局变量判断——该请求头通常会被映射到$_SERVER数组中,同时也需要考虑它通过GET、POST参数或Cookie传递的情况。

以下是实现该检测的PHP代码示例(适配WordPress环境,通过wp_footer钩子输出检测结果):

<?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'); 
?>

内容的提问来源于stack exchange,提问作者Peyton Gregory

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 23:01:33