Example #1
0
 function loadState($store, $name = '', $value = '', $store_type = 'cookie')
 {
     //get possible values
     if (!$value && isset($this->initial_state[$store])) {
         $possible_values = $this->initial_state[$store];
     } else {
         return;
     }
     //count values
     $count = count($possible_values);
     // loop throught values looking for a domain hash match or just using the last value.
     foreach ($possible_values as $k => $value) {
         // check format of value
         if (strpos($value, "|||")) {
             $value = owa_lib::assocFromString($value);
         } elseif (strpos($value, ":")) {
             $value = json_decode($value);
             $value = (array) $value;
         } else {
             $value = $value;
         }
         if (in_array($store, $this->stores_with_cdh)) {
             if (is_array($value) && isset($value['cdh'])) {
                 $runtime_cdh = $this->getCookieDomainHash();
                 $cdh_from_state = $value['cdh'];
                 // return as the cdh's do not match
                 if ($cdh_from_state === $runtime_cdh) {
                     owa_coreAPI::debug("cdh match:  {$cdh_from_state} and {$runtime_cdh}");
                     return $this->setState($store, $name, $value, $store_type);
                 } else {
                     // cookie domains do not match so we need to delete the cookie in the offending domain
                     // which is always likely to be a sub.domain.com and thus HTTP_HOST.
                     // if cookie is not deleted then new cookies set on .domain.com will never be seen by PHP
                     // as only the sub domain cookies are available.
                     owa_coreAPI::debug("Not loading state store: {$store}. Domain hashes do not match - runtime: {$runtime_cdh}, cookie: {$cdh_from_state}");
                     //owa_coreAPI::debug("deleting cookie: owa_$store");
                     //owa_coreAPI::deleteCookie($store,'/', $_SERVER['HTTP_HOST']);
                     //unset($this->initial_state[$store]);
                     //return;
                 }
             } else {
                 owa_coreAPI::debug("Not loading state store: {$store}. No domain hash found.");
                 return;
             }
         } else {
             // just set the state with the last value
             if ($k === $count - 1) {
                 owa_coreAPI::debug("loading last value in initial state container for store: {$store}");
                 return $this->setState($store, $name, $value, $store_type);
             }
         }
     }
 }