I want to display App download message(an image)to users browsing my site from Android device only. So i have developed a plugin to achieve this . Now i want to display this message only first time so, i need to set cookie. Here I'm checking if cookie is set first then don't display message else display message but condition is not working it is showing the message everytime.
<?php
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgsystemandroidmsg extends JPlugin {
function onAfterRender() {
$app = JFactory::getApplication();
$htmlString = $app->getBody();
if ($app->isAdmin()) {
return;
}
$uri = JFactory::getURI();
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if (stripos($ua, 'android') !== false) {
$cookieName = 'mymsgseen';
$cookieValue = $app->input->cookie->get($cookieName);
if ($cookieValue != null && $cookieValue == 1) {
$htmlString = 'cookie is set : ' . $cookieValue;
$app->setBody($htmlString);
} else {
$cookieValue = 1;
$expire = time() + 60 * 60 * 24 * 30;
$app->input->cookie->set($cookieName, $cookieValue, $expire);
$htmlString = 'cookie is not set';
$app->setBody($htmlString);
}
}
}
return true;
}
}
how can i achieve this? how to set and get cookies in joomla 3 ?