creating a cookie using EE and Freeway

I have never played with cookies before. So may be trying to do something cack handed.
I am trying to create a cookie and then when a user looks at another entry page an id is added so I can build a list of pipelined numbers that I can use in an Expression Engine Tag that will then show the user what he has looked at.
At the moment I m trying to use the cookie_plus plugin for EE and this code

{exp:cookie_plus:get name=“mycookie” parse=“inward”}
{exp:weblog:entries limit=“1”}
{exp:cookie_plus:set name=“mycookie” value=“{cookie}{entry_id}|” seconds=“3600”}
{/exp:weblog:entries}
{/exp:cookie_plus:get}

it works but adds three of each entry_id after the first page is left.

Is there another way of doing this?

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Anyone help with this? I only want to create a list like this 45|67|78| as a cookie. Each entry I go into adds a number to the list. It doesnt have to be with Expression Engine I just need to take a cookies existing content and add an extra number and pipeline each time a user goes into a new entry.

thanks Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi

I have never worked with the coocie_plus extention, so I do not know.
I’ve just read that output cannot be used within another EE tag. Could it be that?

# using it you should place the code for setting cookie on top of the page and cookie must be set before any output started
# it is not possible to use retrieved cookie as parameter of other tags.

dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Have a look at the Prototype Cookie extension from Ryan Johnson: http://livepipe.net/extra/cookie

It’s so nice and easy to use, and you will be able to store anything
you want in your cookie using JavaScript, and deserialize it and use
it later in the same page if you need to.

Walter

On Oct 13, 2010, at 5:48 AM, ummedia wrote:

Anyone help with this? I only want to create a list like this 45|67|
78| as a cookie. Each entry I go into adds a number to the list. It
doesnt have to be with Expression Engine I just need to take a
cookies existing content and add an extra number and pipeline each
time a user goes into a new entry.

thanks Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Atelier I mised that. Walter it looks thats what I want but how do I implement it?
I have the cookie.js but there isnt much more information other than what they call an example. Do you have a working example of code I could look at?

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Here’s a simple example.

http://scripty.walterdavisstudio.com/cookie_puss

(In honor of the Beastie Boys)

View source. I’ve got a couple of different examples rolled into one,
with an old-school onclick observer and a modern unobtrusive observer
as well. You can use any syntax you like with Cookie, it’s really very
relaxed that way.

Walter

On Oct 13, 2010, at 1:26 PM, ummedia wrote:

Thanks Atelier I mised that. Walter it looks thats what I want but
how do I implement it?
I have the cookie.js but there isnt much more information other
than what they call an example. Do you have a working example of
code I could look at?

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter I have spent some time looking at the code, it does exactly what I want but it is just taking some time for it to sink in. How do i get it to set the cookie when the page loads using the existing cookie and adding the {entry_id} of the existing page. I can do the entry id bit using EE tags its the javascript I am not familiar with.

thanks as usual

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You can get EE to write the variable into the JavaScript on the page,
before the browser ever sees it. Here’s how I would do that in raw
PHP, you can translate into EE tags:

<!-- somewhere inside the page head,
	after the libraries are loaded -->
<script type="text/javascript">
document.observe('dom:loaded',function(){
	var this_page = <?php echo $entry_id; ?>;
	var arr = (Cookie.get('myHistory')) ?
		Cookie.get('myHistory').split('|') : [];
	arr.push(this_page);
	Cookie.set('myHistory',arr.join('|'));
});
</script>

That block of code would rely on the page already including the three
required script libraries, and if you want to use Protaculous for
this, you would drop the outer document.observe block, since the
Action writes that for you.

What this does is set an observer on the page, which is similar to
doing onload=“whatever()” in the body tag. The difference is that you
can have multiple observers on the same event, and they stack and
don’t block each other.

So because my PHP code wrote whatever the current value of $entry_id
was into the JavaScript before the JavaScript ever reached the browser
(i.e.: back inside the server while the page was being assembled),
when the browser evaluates the JavaScript, there is an actual value
already written into the JS and that gets used to append to your
history string.

Walter

On Oct 14, 2010, at 6:02 AM, ummedia wrote:

Thanks Walter I have spent some time looking at the code, it does
exactly what I want but it is just taking some time for it to sink
in. How do i get it to set the cookie when the page loads using the
existing cookie and adding the {entry_id} of the existing page. I
can do the entry id bit using EE tags its the javascript I am not
familiar with.

thanks as usual

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It took me ages to link to the libraries but it looking good Walter. Cant wait to actually use it to show my history. leading to one last question, OK maybe two!
How do I return just the cookie as text into my EE tags and lastly how long does the cookie last?

thanks for your time Walter

kind regards

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You’ll have to find a cookie reader for EE – it’s pretty simple in
PHP, and EE is written in PHP, so it shouldn’t be very hard. The
syntax to read a cookie in PHP is just this:

$your_variable = $_COOKIE['cookieName'];

However, unlike the JavaScript example, you can’t write and read the
cookie in the same request. If you write the cookie you have to wait
until the next page load to read the new value back out again in PHP.

You could also inject the value of the cookie into your page using
JavaScript. Have a look at my example page for code to do just that
(look for anything that includes the function update() in it).

As long as you know the name of the cookie you’re trying to read, and
are asking from within the same domain, it doesn’t matter what method
you use to access the cookie. So you could write the value with PHP
and read it with JavaScript, or vice-versa.

Cookies last as long as you set them for. By default, the LivePipe
cookie class sets them to be immortal, but you can set them for
different ages if you want to have it expire automatically. Have a
browse through the source, it’s pretty readable.

Walter

On Oct 14, 2010, at 3:21 PM, ummedia wrote:

It took me ages to link to the libraries but it looking good Walter.
Cant wait to actually use it to show my history. leading to one last
question, OK maybe two!
How do I return just the cookie as text into my EE tags and lastly
how long does the cookie last?

thanks for your time Walter

kind regards

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Eccellent thank you Walter, I dont need it on the same page so that will do fine. I will change the lifespan otherwise you’ll end up with a huge pipeline of numbers.

kind regards

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter
I know you dont use EE but I have I think a quote problem and wondered if you had a way round it.
I am trying to retrieve to a page the cookies that have been created I have it working on the front page of digitalwatchlibrary perfectly but this page works alittle differently. Anyway here is the code

{if segment_4 == "History"} {embed="DWL/segmentsearch" search_type='entry_id="<?php $history = $_COOKIE['myHistory']; echo $history; ?>"'} {/if}
I have enable php turned on on my page and if I return the php code on its own it returns the cookie pipeline as soon as I add it to the rest of the code the page breaks down. As I am already using php I wondered if I could create the whole line of code using that.

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

There’s probably an EE tag that lets you put raw php in the page, but I don’t think you can do just what you have there. Also, if you want to simplify getting the cookie value back out, try this:

<?= $_COOKIE['myHistory'] ?>

That’s the short-form notation for print this variable.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter Im not having a huge amount of luck with that page I think i’ll come back to it later.
One problem I am noticing is that if you go to digitalwatchlibrary.com even with a cookie already there it doesnt show the images i the pipeline above Deja vu header. Only when you got to an entry and return to the homepage do they all show up. Is there ant easy fix for this or is it just how it works?

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’m not sure what I’m supposed to be seeing here. Hard to say what
could be wrong. When I first come to the site, I see a zillion
different watches in that area. Once I visited a page, I saw only one.
Are you pulling that list of images from somewhere random when a brand
new user appears on the site?

Walter

On Oct 16, 2010, at 1:29 PM, ummedia wrote:

Thanks Walter Im not having a huge amount of luck with that page I
think i’ll come back to it later.
One problem I am noticing is that if you go to
digitalwatchlibrary.com even with a cookie already there it doesnt
show the images i the pipeline above Deja vu header. Only when you
got to an entry and return to the homepage do they all show up. Is
there ant easy fix for this or is it just how it works?

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I am not sure why I get the 35 watches I think its because there is no cookie being found so no pipeline is being entered so all watches are returned limited to 35.
I would expect this on very first entrance by user until I work out if I can do a conditional. What I cant work out is that when you go back to the site by typing digitalwatchlibrary.com to a new page your existing cookie pipeline isnt shown unless its just on my computer.

thanks for your time Walter

kind regards

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You may be seeing the difference between www.digitalwatchlibrary and
digitalwatchlibrary. Cookies are domain-sensitive unless you tell them
not to be. And by domain, I mean subdomain-sensitive, too.

So if you set a cookie on www and then came back without the dubs, you
would appear, cookie-wise, to be a completely new person, never been
there before, etc.

Walter

On Oct 16, 2010, at 2:53 PM, ummedia wrote:

digitalwatchlibrary.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter
You are right!

can I set it for both the www.digital and the digital?

I tried changing it in my EE settings but that didnt make a difference.

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hmmm. Not with the Cookie script you’re using. I just had a look back
at a previous version – I could have sworn you could set the domain
using this class – and it’s not there either.

I just made a fork of Livepipe on Github, and here’s a version which
will let you define the domain when you write the cookie:

To use, make the following changes. Where you have:

Cookie.set('myHistory',arr.join('|'));

Make it read like this:

Cookie.set('myHistory',arr.join('|'),null,
	'domain=.yourdomain.com;path=/');

You don’t have to split it across two lines like that, I’m just trying
to get Apple Mail to behave with source code in it. Note the dot in
front of the domain name. I believe that is important, at least it is
in PHP. You may need to experiment with leaving that off, and see if
it makes any difference.

Walter

On Oct 23, 2010, at 7:41 AM, ummedia wrote:

Walter
You are right!

can I set it for both the www.digital and the digital?

I tried changing it in my EE settings but that didnt make a
difference.

many thanks

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

No difference Walter. I tried with the dot and without, still doesnt recognize

Adam


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options