Set and get cookies in Joomla CMS

Now, it’s time to learn how to use cookies in Joomla!
If you want save some information in cookie or get some value from cookies then you can use $jcookie = JFactory::getApplication()->input->cookie;
Example ↓

$app = JFactory::getApplication();
$jinput = $app->input;
$jcookie  = $jinput->cookie;

$cookie_value = $jcookie->get( 'cookie_name', null); // Get cookie data  ($name, $defaultValue)

$jcookie->set( 'cookie_name', 'cookie_value', 0); // Set cookie data ($name, $value, $expire) $expire == 0: cookie lifetime is of browser session.


Also, you cas see article about set/get session values in Joomla!
To reset the value you need to do the following ↓

$app = JFactory::getApplication();
$jinput = $app->input;
$jcookie  = $jinput->cookie;

$jcookie->set('cookie_name', null, time() - 1); // Remove cookie