We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Is $this->EE->input->cookie() broken?

Development and Programming

Brian M.'s avatar
Brian M.
529 posts
14 years ago
Brian M.'s avatar Brian M.

I’ve been having some issues using $this->EE->input->cookie() in a template. I have this code:

<?php
echo "'" . $_COOKIE['announcement'] . "' = '" . $this->EE->input->cookie('announcement') . "'";
?>

which returns:

'Show' = ''

I tried loading the cookie helper and using get_cookie(‘announcement’) and that doesn’t return anything either.

The cookie shows up fine when I look at the browser cookies.

Am I doing something wrong? Thanks!

EDIT: EE 2.3.1

       
artminister's avatar
artminister
159 posts
14 years ago
artminister's avatar artminister

I think you need to add exp_ prefix to your cookie.

http://ellislab.com/forums/viewthread/195665/

       
Brian M.'s avatar
Brian M.
529 posts
14 years ago
Brian M.'s avatar Brian M.

Hmmm, I thought that was it, I think I remember the same thing happening in EE1?

Now I have both announcement and exp_announcement cookies (just while testing). So I have this:

<?php
echo "'" . $_COOKIE['announcement'] . "' = '" . $this->EE->input->cookie('announcement') . "'";
echo "
";
echo "'" . $_COOKIE['exp_announcement'] . "' = '" . $this->EE->input->cookie('exp_announcement') . "'";
?>

and that returns:

'Hide' = ''
'Hide' = ''
       
artminister's avatar
artminister
159 posts
14 years ago
artminister's avatar artminister

You have to set the cookie name with exp_ prefix. Eg:

setcookie("exp_ announcement","asda");    
echo $this->EE->input->cookie('announcement');
       
Brian M.'s avatar
Brian M.
529 posts
14 years ago
Brian M.'s avatar Brian M.

I did that in the previous example with javascript. I now have it in PHP as well:

<?php                 
setcookie('exp_announcement','Hide');
echo "'" . $_COOKIE['announcement'] . "' = '" . $this->EE->input->cookie('announcement') . "'";
echo "
";
echo "'" . $_COOKIE['exp_announcement'] . "' = '" . $this->EE->input->cookie('exp_announcement') . "'";
?>

which returns:

'Hide' = ''
'Hide' = ''
       
artminister's avatar
artminister
159 posts
14 years ago
artminister's avatar artminister

Hmm.. Your code works fine for me. I am one EE 2.3.1

$this->EE->input->cookie(‘announcement’) returns ‘exp_announcement’ cookie

       
Brian M.'s avatar
Brian M.
529 posts
14 years ago
Brian M.'s avatar Brian M.

Yikes - I had the prefix set to something else. Thanks for helping.

       
Brian M.'s avatar
Brian M.
529 posts
14 years ago
Brian M.'s avatar Brian M.

Ahhh - keep in mind not to put in the underscore if you have a prefix:

use exp rather than exp_

that’s what ended up breaking things. Oops.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.