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
相关产品推荐
相关产品推荐

