Hi Laisvunas, thanks for your help.
I’ve created a simple template to test if I can retrieve the cookie by just using PHP. (I haven’t created an EE plugin in my life, so I don’t have the SQL query wrapped in one. I should try!)
But the test is meant to simply output the value of the cookie:
From plugin: {exp:cookie_plus:get name="user_in"}
From php: <?php echo $_COOKIE["user_in"]; ?>
Using your plugin it works perfectly, but this is what I get from PHP in my browser:
Notice: Undefined index: user_in in /home/.manet/cret/costaricaexotictravel.com/cretee/core/core.functions.php(635) : eval()'d code on line 27
What could this be?
Thanks man!
Hi all,
this is my first attempt at using cookies and thought I would give this plug-in a try. Potentially it sounds great but i’m having no luck retrieving a cookies value.
i’m using this code to set my cookie:
{exp:cookie_plus:set name="mylocation" value="west" seconds="0"}
setting it to “0” because I want a session cookie as described.
to retrieve i’m using:
{exp:cookie_plus:get name="mylocation"}
{if cookie=="west"}
item one
{if:else}
item two
{/if}
{/exp:cookie_plus:get}
I am using the retrieve info within an include that is embedded within the page.
Cheers in advance!
Ok here goes. 😊
My current website is http://www.reeb.com/index.php/index/ which shows product info for EAST location.
I am being asked to create a second web page that will highlight WEST coast product info http://www.reeb.com/index.php/indexWest/
My header and navigation along with other elements on the page are created using includes/embeds http://expressionengine.com/docs/templates/embedding_templates.html
I want the REEB logo and the HOME button to link to the home page of EAST when the user has selected EAST and WEST when the user has selected WEST.
My branding include code:
<div id="branding">
<a href="http://www.reeb.com/index.php/indexWest/%22name=%22top">/images/branding/reebLogo.jpg</a>
{if:else}
<a href="http://www.reeb.com/index.php/index/">/images/branding/reebLogo.jpg</a>
{/if}
{/exp:cookie_plus:get}
</div>
My page code:
{exp:cookie_plus:set name="mylocation" value="west" seconds="0"}
{assign_variable:pageTitle="REEB | Welcome to REEB"}
{assign_variable:pageHeader="Home"}
{assign_variable:pageID="home"}
{assign_variable:css_style="home"}
{assign_variable:my_template_group="weblog"}
{embed="includes/doc_type"}
<head>
{embed="includes/metadata"}
<title>{pageTitle}</title>
{embed="styles/{css_style}"}
{embed="includes/javascript"}
</head>
<body id="{pageID}">
{embed="includes/login"}
{embed="includes/select_location"}
<div id="container">
{embed="includes/branding"}[color=red]<!-- branding included here -->[/color]
<div id="navSubWrapper"> {embed="includes/subNav"} </div>
<div id="navMainWrapper"> {embed="includes/mainNav"} </div>
<div id="content">
<div id="contentMain">
<div id="highlightWrapper">
<div id="highlightContent">
<div id="left"><!-- Highlight left image BEGIN -->
{exp:gallery:entries gallery="highlight_banner_3" category="39" orderby="random" limit="1" dynamic="off"}
<a href="http://{custom_field_one}">{image_url}</a>
{/exp:gallery:entries}
</div><!-- Highlight END -->
<div id="right"><!-- Highlight right image BEGIN -->
{exp:gallery:entries gallery="highlight_banner_2" category="11" orderby="random" limit="1" dynamic="off"}
<a href="http://{custom_field_one}">{image_url}</a>
{/exp:gallery:entries}
</div><!-- Highlight END -->
</div>
</div>
<div id="pageTitle">
</div>
<div id="mainTextWrapper">
<div id="newProducts">
<h2>New Products</h2>
{exp:weblog:entries weblog="weblog" category="27" orderby="date" sort="desc" limit="5" disable="trackbacks"}
<div class="productHighlightImage">{image}</div>
<ul>
<li> <a href="http://{permalink="><span class="yellow">{title}</span></a></li>
</ul>
{summary}
<a href="http://{permalink=">Read More</a><br><br>
<div class="hr" align="center">/images/layout/hr.jpg</div>
{/exp:weblog:entries}
</div>
<div id="spotlight">
<h2>Spotlight</h2>
{exp:weblog:entries weblog="weblog" category="25" orderby="date" sort="desc" limit="3" disable="trackbacks"}<br>
{title}<br>
{image}
{summary}
<h4>{comment_total} comments // {entry_date format="%F %d, %Y"}</h4>
<a href="http://{permalink=">Read More</a>
<div class="hr" align="center">/images/layout/hr.jpg</div>
{/exp:weblog:entries}
</div>
<div id="highlightColumn"> <!-- Highlight Column BEGIN -->
{embed="includes/product_categories"}
<div id="newsHighlight">
<h2>Latest News</h2>
<ul>
{exp:weblog:entries weblog="weblog" orderby="date" sort="desc" limit="5" disable="trackbacks" dynamic="off"}
<li><a href="http://{permalink=">{title}</a><br><h4>// {entry_date format="%F %d, %Y"}</h4></li>
{/exp:weblog:entries}
</ul>
<a href="http://www.reeb.com/index.php/weblog/">View All</a>
</div>
{embed="includes/newest_media"}
</div><!-- Highlight Column END-->
</div>
</div>
{embed="includes/manufacturer_scrolling_logos"}
{embed="includes/site_info"}
</div>
{embed="includes/footer_javascript"}
</body>
</html>
Like I said i’m new to this stuff, maybe this is not the best way to achieve this??
Hi cicconedesign,
It is irrelevant that the code that sets the cookie is on the main template and the code that reads the cookie is on embedded template. Both setting cookie and reading it should work. That is, the first time you load the page cookie will be set, the second time and so on cookie will be both set and retrieved. If it does not work this way for you I have no idea what might be the cause.
maybe this is not the best way to achieve this??
Really, it is wrong way to achieve functionality you need, because the right link will be displayed only starting from the second load of the page. You would better use URL segment variables. The code would be as follows:
{if segment_1=="indexWest"}
<a href="http://www.reeb.com/index.php/indexWest/">/images/branding/reebLogo.jpg</a>
{if:else}
<a href="http://www.reeb.com/index.php/index/">/images/branding/reebLogo.jpg</a>
{/if}
BUG REPORT:
Cookies saved on my browsers (Safari 3.2.1 mac, Firefox 3.0.5 mac) are having an underscore added to the cookie name.
I’m saving a cookie called “subscribed” but it’s stored as “subscribed” (EE’s cookies start with exp for example exp_last_visit whereas this plugin’s cookies start with exp__ for example exp__subscribed). I’m using this plugin’s “script” method.
The workaround seems to be to save it as “subscribed” but refer to it as “_subscribed” when retrieving it.
Note that I haven’t tried this on Windows.
Anyone else seen this?
hi there,
it should be a bug because it doesn’t work as expected or as documented. in order to read a cookie previously created by this plugin, an underscore must be added to the name of the cookie or this plugin won’t find it. at least in the two browsers i mentioned. sounds like a bug to me.
in order to read a cookie previously created _by this plugin_, an underscore must be added to the name of the cookie or this plugin won’t find it.
Do you mean the plugin cannot read a cookie it has set earlier? That would really be a bug.
Can you describe an example of such behaviour, so that I could reproduce it?
Yes, this plugin cannot read a cookie it has set earlier. I thought that was clear in my original post.
When a user subscribes, I save a cookie called “subscribed”:
{exp:cookie_plus:set name="subscribed" value="1" seconds="16000000" method="script"}
When I try to retrieve it:
{exp:cookie_plus:get name="subscribed"}
{if cookie != "1" }
{!-- show the subscription form --}
{/if}
{/exp:cookie_plus}
It doesn’t work. The subscription form is always shown.
So I checked my cookies, and I see a cookie named “exp__subscribed”. There’s an extra underscore there. So I made this change:
{exp:cookie_plus:get name="_subscribed"}
{if cookie != "1" }
{!-- show the subscription form --}
{/if}
{/exp:cookie_plus}
And that works. Again, my set uses the name “subscribed” but my get needs the name “_subscribed”.
The above behavior is the same on Safari 3.2.1 mac, Firefox 3.0.5 mac.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.