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.


defined('_JEXEC') or die;

class plgsystemandroidmsg extends JPlugin {

    function onAfterRender() {
        $app = JFactory::getApplication();
        $htmlString = $app->getBody();
        if ($app->isAdmin()) {
        $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;
                } else {
                    $cookieValue = 1;
                    $expire = time() + 60 * 60 * 24 * 30;
                    $app->input->cookie->set($cookieName, $cookieValue, $expire);
                    $htmlString = 'cookie is not set';
        return true;


how can i achieve this? how to set and get cookies in joomla 3 ?

  • This source code seems Ok to me.
    – Anibal
    Commented Sep 25, 2014 at 11:46
  • @Anibal, Then, What should be the issue here ? I couldn't understand also why it isn't working?
    – Ram Guru99
    Commented Sep 25, 2014 at 12:00
  • This is more for people googling their way here like me, but try setting the fourth parameter in cookie->set() to '/'. This makes the cookie available across the whole site, whereas the default value just stores it at the current path.
    – Obscerno
    Commented Apr 6, 2023 at 3:02

1 Answer 1


First of all you could first try to fit this code in your template. If may give you more flexibility there.

onAfterRender does not seem right for me to fiddle the content and to set cookies / read cookies.

Are you sure that your plugin is actually being called? Anyway, check your browser console to see the status.

  • I have tried this on my localhost with joomla default template, it is working fine, do you have any suggestions why it is not working over dedicated server?
    – Ram Guru99
    Commented Sep 30, 2014 at 12:59
  • Is Joomla managing to send the session cookies? Commented Sep 30, 2014 at 13:11
  • Yes, It sets the session cookies. I verified it in firefox
    – Ram Guru99
    Commented Oct 8, 2014 at 4:46
  • This is working fine with same installation on localhost but not over dedicated hosting server. Please Suggestions
    – Ram Guru99
    Commented Oct 9, 2014 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.