close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Storing multiple ENTERED values in a cookie

Thread began 4/04/2010 12:27 pm by msummers194171 | Last modified 4/13/2010 2:49 pm by Jimmy Wu | 1117 views | 5 replies |

msummers194171

Storing multiple ENTERED values in a cookie

I have a page that has a fair number of (PHP) session variables created. I want to save these session variables in a cookie so that I can return to those same variables at a later date. How can I best do this given the current UI for the Cookies Toolkit? The "Entered Value" option appears to be good for only a single value (without an associated name to make a name/value pair).

Murray

Sign in to reply to this post

Eric Mittman

You should try this with the server side cookies, you would want to add in a set cookie server behavior for each of the session variables that you have on the page. This should create the individual cookies based on the session variable values. You could then load these back into the session variables with the set session value server behaviors, one for each cookie.

Sign in to reply to this post

msummers194171

Eric:

Thanks! I have a much better way - discovered in the meantime! It involves the use of the serialize() and unserialize() PHP commands, which seem ideal for this kind of use!

I serialize the ENTIRE $_SESSION array, and pass it to the cookie as a single entered value, e.g.

<?php $foo=serialize($_SESSION); ?>

I then use <?php echo $foo; ?> as the cookie's value in the behavior.

To read this value, I can use this -

<?php $_SESSION=unserialize('cookiename'); ?>

and I'm back where I started with the session variables all set up!

This involves only a single cookie, rather than the multiple ones you suggested. With a fair number of session variables, creating individual cookies for each becomes tedious!

Sign in to reply to this post

msummers194171

Just an additional note. I have found that you need to encode the data before writing and after reading so that the serialize steps work properly, e.g.,

base64_encode(serialize(...))

and

unserialize(base64_decode(...))

Sign in to reply to this post

Eric Mittman

Thanks for posting back about the encoding of the serialized session array. I have used the serialize function like this in the past with good results. It will also be harder for anyone to pick through the values in the cookie if it is serialized like this. Good work, I'm bookmarking this one for future reference.

Sign in to reply to this post

Jimmy Wu

I have responded to your post in this other thread. Please do not keep posting in multiple threads and stick to this one:
showthread.php?t=12072

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...