variables - PHP Cookie Controls -
i working logic operator create cookie containing string of values depending on user's traffic path through website.
on web page have following variable
$lgc_code = '3'
and cookie control set follows:
if ($lgc_code != '') { $lgc=$lgc_code; // check cookie if (isset($_cookie['lgc_cntl'])) { // read cookie $lgc_codes=$_cookie['lgc_cntl']; // check triggers in cookie $expencarr = explode(",", $lgc_codes); foreach($expencarr $code){ if ($code==$lgc_code) {$found='yes';} } if (isset($found)) { $lgc_codes=$_cookie['lgc_cntl']; } else { $lgc_codes=$_cookie['lgc_cntl'].','.$lgc; } } else { $lgc_codes=$lgc; } // add campaign cookie setcookie('lgc_cntl',$lgc_codes,time() + (86400 * 365), "/", ".domain.com"); // 86400 = 1 day } else { $lgc = '1'; if (isset($_cookie['lgc_cntl'])) { // read cookie $lgc_codes=$_cookie['lgc_cntl']; // check triggers in cookie $expencarr = explode(",", $lgc_codes); foreach($expencarr $code){ if ($code==$lgc_code) {$found='yes';} } if (isset($found)) { $lgc_codes=$_cookie['lgc_cntl']; } else { $lgc_codes=$_cookie['lgc_cntl'].','.$lgc; } } else { $lgc_codes=$lgc; } // add campaign cookie setcookie('lgc_cntl',$lgc_codes,time() + (86400 * 365), "/", ".domain.com"); // 86400 = 1 day }
this works single variable being passed page cookie need able pass multiple variables @ once while comparing them cookie.
for example if page variable reads "1, 5, 10" , cookie contains "1 , 10" variable 5 need added.
currently, if add multiple variables on page, cookie duplicates them every time page loaded end "1,1,5,10,10"
how can modify code below compare variables , add ones not found in cookie already?
if $lgc_code
may contain comma separated values, should converted array before comparison. try changing these lines
// check triggers in cookie $expencarr = explode(",", $lgc_codes); foreach($expencarr $code){ if ($code==$lgc_code) {$found='yes';} }
to
// check triggers in cookie $expencarr = explode(",", $lgc_codes); $thispagearr = explode(",", $lgc_code); $newcodes = array_diff($thispagearr, $expencarr); if (!empty($newcodes)) { $found = 'yes'; }
Comments
Post a Comment