doupingpeng7567 2013-01-30 15:37
浏览 16
已采纳

PHP很难理解这个功能[关闭]

I have this function written by another programmer, but he quit long ago.

I was trying to understand this function that he wrote, but I don't fully understand it.

It's getting a token from the csv file, and the quantity should depend how much I choose. But what the force_plaform variable does? Also what the $_GET x-parameter and $_COOKIE x-parameter do?

// Get a purchaselink from a given token (if one exists) and a given csv
function getPurchaseLink($token, $csvfile, $force_platform = "", $quantity = 1)
{
$fp = fopen($csvfile, 'r', true);
$columns = fgetcsv($fp, 1024, ',');

while (($row = fgetcsv($fp, 1024, ","))) {
    $row = array_combine($columns, $row);
    if ($row['purchaseToken'] == $token) {
        $purchaseLink = $row;
        break;
    }
}

// Default to pucharse link
$url = http://www.purchase.com//?p1=zzM5X9k4dF%2BDzrTnixoaKw3Fg7wZ8h5pkjp%2BLEidTXBg40xOjcFj5PtPlQniMskLm0W3ti65mE2KafUifZe9dZAcE&ref=purchase.com&style=146&ga=UA-2689090-1&C1=C01507;1;0&C2=C0508;0;0;
if ($url) {     
  // Convert GET x-parameters to cmp, mkey1 and mkey2 if they are present
  $append = "";
  if((isset($_GET["x-source"])) && ($_GET["x-source"] != "")) {
    $append = "&cmp=source_" . $_GET["x-source"];
    $nextParameter = "x-" . $_GET["x-source"];
    $counter = 1;
    $searching = TRUE;
    while(($searching) && ($counter <= 2)) {
      if((!isset($_GET[$nextParameter])) || ($_GET[$nextParameter] == "")) {
        $searching = FALSE;
      }
      else {
        $append .= "&mkey" . $counter . "=" . str_replace("x-", "", $nextParameter) . "_" . $_GET[$nextParameter];
        $nextParameter = "x-" . $_GET[$nextParameter];
    $counter += 1;
      }
    }
  }
  // Convert COOKIE x-parameters to cmp, mkey1 and mkey2 if they are present and there are no GET x-parameters
  if(($append == "") && (isset($_COOKIE["x-source"])) && ($_COOKIE["x-source"] != "")) {
    $append = "&cmp=source_" . $_COOKIE["x-source"];
    $nextParameter = "x-" . $_COOKIE["x-source"];
    $counter = 1;
    $searching = TRUE;
    while(($searching) && ($counter <= 2)) {
      if((!isset($_COOKIE[$nextParameter])) || ($_COOKIE[$nextParameter] == "")) {
        $searching = FALSE;
      }
      else {
        $append .= "&mkey" . $counter . "=" . str_replace("x-", "", $nextParameter) . "_" . $_COOKIE[$nextParameter];
        $nextParameter = "x-" . $_COOKIE[$nextParameter];
    $counter += 1;
      }
    }
  }
  // Return upclick purchase link   
  return $url . $append;
}

if ($quantity != 1) {
    $url .= "&quantity=" . $quantity;
}

// Pass on tracking parameters from URI query and cookies
$append = "";
foreach($_GET as $parameter => $value) {
    if(strpos($parameter, "x-") === 0 || $parameter == "tracking" || $parameter == "serial" || $parameter == "affiliate") {
        $append .= "&" . $parameter . "=" . $value;
    }
}
if (empty($append)) {
    foreach($_COOKIE as $parameter => $value) {
        if(strpos($parameter, "x-") === 0) {
            $append .= "&" . $parameter . "=" . $value;
        }
    }
}

$append = str_replace("x-tracking", "tracking", $append);
$append = str_replace("x-affiliate", "affiliate", $append);
$append = str_replace("&serial=", "&x-serial=", $append);

return $url . $append;
 }
  • 写回答

1条回答 默认 最新

  • duanjuebin2519 2013-01-30 15:45
    关注

    The function is building a query string (URL) and returning it. What the program does once it calls that URL is not up to this code, but the code on the page that gets called. This code just generates a URL. As to force_plaform, it does not appear to be being used in the function at all (just in the function header). It is an unused variable. As to the $_GET and $_COOKIE variables, the code is simply checking if they exist, and appending them to the query string if so.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。