我尝试在PHP会话中使用Google UTM查询字符串,然后用JSON解析它。我试图确保我没有收到任何错误。我想要对具有google utm参数(adwords广告系列)的网址查询字符串进行会话,然后解析这些值并将其插入到隐藏的表单字段中。这看起来是否正确?我的代码如下。让我知道。谢谢!
<?php
if (!session_id())
{
session_start();
}
if (!isset($_SESSION['googy']))
{
$_SESSION['googy'] = $_SERVER["QUERY_STRING"];
}
if (isset ($_SESSION['googy']) )
$goo .= $_SESSION['googy'];
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var query = '<?php echo $goo; ?>';
query = query.replace(/%20/g," ");
query = query.replace(/%21/g,"!");
query = query.replace(/%22/g,'"');
query = query.replace(/%23/g,"#");
query = query.replace(/%24/g,"$");
query = query.replace(/%25/g,"%");
query = query.replace(/%26/g,"&");
query = query.replace(/%27/g,"'");
query = query.replace(/%28/g,"(");
query = query.replace(/%29/g,")");
query = query.replace(/%2A/g,"*");
query = query.replace(/%2B/g,"+");
query = query.replace(/%2C/g,",");
query = query.replace(/%2D/g,"-");
query = query.replace(/%2E/g,".");
query = query.replace(/%2F/g,"/");
var parameters = {};
if (query) {
var search_arr = query.split("&");
for (var item in search_arr) {
if (search_arr[item]) {
var item_arr = search_arr[item].split("=");
if (item_arr[1]) {
parameters[item_arr[0]] = item_arr[1];
}
}
}
}
if (JSON.stringify(parameters) != '{}') {
for (var prop in parameters) {
jQuery("#" + prop).val(parameters[prop]);
}
}
});
</script>