Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Hard time understand this function
    text
    copied!<p>I have this function written by another programmer, but he quit long ago.</p> <p>I was trying to understand this function that he wrote, but I don't fully understand it.</p> <p>It's getting a <strong>token</strong> from the <strong>csv file</strong>, and the quantity should depend how much I choose. But what the <strong>force_plaform</strong> variable does? Also what the <strong>$_GET</strong> x-parameter and <strong>$_COOKIE</strong> x-parameter do?</p> <pre><code>// 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&amp;ref=purchase.com&amp;style=146&amp;ga=UA-2689090-1&amp;C1=C01507;1;0&amp;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"])) &amp;&amp; ($_GET["x-source"] != "")) { $append = "&amp;cmp=source_" . $_GET["x-source"]; $nextParameter = "x-" . $_GET["x-source"]; $counter = 1; $searching = TRUE; while(($searching) &amp;&amp; ($counter &lt;= 2)) { if((!isset($_GET[$nextParameter])) || ($_GET[$nextParameter] == "")) { $searching = FALSE; } else { $append .= "&amp;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 == "") &amp;&amp; (isset($_COOKIE["x-source"])) &amp;&amp; ($_COOKIE["x-source"] != "")) { $append = "&amp;cmp=source_" . $_COOKIE["x-source"]; $nextParameter = "x-" . $_COOKIE["x-source"]; $counter = 1; $searching = TRUE; while(($searching) &amp;&amp; ($counter &lt;= 2)) { if((!isset($_COOKIE[$nextParameter])) || ($_COOKIE[$nextParameter] == "")) { $searching = FALSE; } else { $append .= "&amp;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 .= "&amp;quantity=" . $quantity; } // Pass on tracking parameters from URI query and cookies $append = ""; foreach($_GET as $parameter =&gt; $value) { if(strpos($parameter, "x-") === 0 || $parameter == "tracking" || $parameter == "serial" || $parameter == "affiliate") { $append .= "&amp;" . $parameter . "=" . $value; } } if (empty($append)) { foreach($_COOKIE as $parameter =&gt; $value) { if(strpos($parameter, "x-") === 0) { $append .= "&amp;" . $parameter . "=" . $value; } } } $append = str_replace("x-tracking", "tracking", $append); $append = str_replace("x-affiliate", "affiliate", $append); $append = str_replace("&amp;serial=", "&amp;x-serial=", $append); return $url . $append; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload