PHP中的$ _GET没有得到utm值

时间:2016-10-04 22:48:08

标签: php apache

我正在尝试使用此PHP代码打印/回显utm_source,utm_medium和utm_campaign查询值;

echo $_GET['utm_source'];

但奇怪的是,由于某些未知原因我的服务器上没有打印值,当我将utm_source替换为test_source之类的东西时,我能够看到print中的值。

从未遇到任何此类问题,任何人都可以在这里指导我。

<!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>

2 个答案:

答案 0 :(得分:0)

您的原始问题引用了此代码

<!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>

如果您在此语句中添加echo,则可以使用

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

使用

进行测试时
test.com/test.php?utm_source=1

更安全的PHP代码

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

答案 1 :(得分:0)

如果您的网站使用的是WPengine,您将无法使用PHP从URL中获取utm变量(以及utm之后的任何其他变量)。出于性能原因,某些Web主机专门针对服务器请求定位并删除这些utm参数。棘手的部分是,utm变量仍然保留在URL中,这意味着如果需要,可以使用Javascript检索它们。

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

相关问题