public function add()
    {
        if (!headers_sent()) {
            // Set the cookie via PHP headers
            $added = setcookie(
                $this->name,
                $this->value,
                round(time() + 60 * 60 * 24 * $this->lifetime),
                $this->path,
                $this->host
            );
        } else {
            //Headers have been sent use JavaScript to set the cookie
            echo "<script>";
            echo '
              function setCookie(c_name,value,expiredays){
                var exdate=new Date();
                exdate.setDate(exdate.getDate()+expiredays);
                document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toUTCString()) + "; domain="+ escape("' . $this->host . '") + "; path=" + escape("' . $this->path . '");
              }
            ';
            echo "setCookie('{$this->name}','{$this->value}',{$this->lifetime})";
            echo "</script>";
            $added = true;
        }

        return $added;
    }