简体   繁体   中英

Cookie not setting expire date correctly

Im trying to set a cookie for 30 days but for some reason after its set it shows expires "session". Verified on Firefox and Chrome. I cant figure out what I am doing wrong. Any help is appreciated!

Here is my code:

  $name = 'db_mc';
  $value = $mc_cid . '-' . $mc_eid;
  $time = time()+3600*24*30;
  $path = '/';
  $domain = 'www.testmage.local';

  $cookie = Mage::getSingleton('core/cookie');
  $cookie->set($name,$value,$time,$path,$domain);

Update:

I tested setcookie() and that works correctly. So I assume I have to use that. Does anyone know why the Magento version only sets for the session though?

Magento's cookies expiry datetime set always in seconds, you need to convert your date or time in seconds then you will set your cookies in magento accordingly.

Cookies set for one month in magento:

$expire = strtotime(date("m/d/Y, H:i:s A", time() + 60 * 60 * 24 * 30));

Output: 09/13/2015, 10:43:39 AM (calculate with current date).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM