douboshan1466 2016-10-04 22:48
浏览 42

PHP中的$ _GET没有得到utm值

I am trying to print / echo utm_source, utm_medium and utm_campaign query values using this PHP code;

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.

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>
  • 写回答

2条回答 默认 最新

  • dongping6974 2016-10-04 23:32
    关注

    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

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

    when tested using

    test.com/test.php?utm_source=1
    

    A safer piece of PHP code would be

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

报告相同问题?