简体   繁体   English

PHP 中的 $_GET 没有获得 utm 值

[英]$_GET in PHP not getting utm values

I am trying to print / echo utm_source, utm_medium and utm_campaign query values using this PHP code;我正在尝试使用此 PHP 代码打印/回显 utm_source、utm_medium 和 utm_campaign 查询值;

echo $_GET['utm_source'];

But strangely for some unknown reason on my server its not printing the values, when I replace utm_source to something else like test_source I am able to see the value in print.但奇怪的是,由于某些未知原因在我的服务器上没有打印值,当我将 utm_source 替换为 test_source 之类的其他内容时,我能够看到打印中的值。

Never faced any such issue, can anyone guide me here.从来没有遇到过任何这样的问题,任何人都可以在这里指导我。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php echo $_GET['utm_source']; ?>

</body>
</html>

Your original question quoted this code您的原始问题引用了此代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php $_GET['utm_source']; ?>

</body>
</html>

If you add an echo to this statement it will work如果您向此语句添加echo ,它将起作用

<?php echo $_GET['utm_source']; ?>

when tested using当测试使用

test.com/test.php?utm_source=1

A safer piece of PHP code would be一段更安全的 PHP 代码是

<?php 
    if ( isset($_GET['utm_source']) ) {
        echo $_GET['utm_source']; 
    } else {
        echo 'the parameter utm_source is missing';
    }
?>

If your site is using WPengine, you will not be able to get the utm variables (and any additional variables after the utm's) out of the URL using PHP.如果您的站点使用 WPengine,您将无法使用 PHP 从 URL 中获取 utm 变量(以及 utm 之后的任何其他变量)。 Some web hosts specifically target and remove these utm parameters from server requests for performance reasons.出于性能原因,某些 Web 主机专门针对并从服务器请求中删除这些 utm 参数。 Tricky part is, utm variables are still going remain in the URL which means that you can retrieve them using Javascript instead if you need to.棘手的部分是,utm 变量仍然保留在 URL 中,这意味着您可以在需要时使用 Javascript 来检索它们。

Source: WPengine article https://wpengine.com/support/utm-gclid-variables-caching/来源:WPengine 文章https://wpengine.com/support/utm-gclid-variables-caching/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM