cookies and arrays in php

Date: 20th October 2007 at 1:27 am | Filed under: development, scripts | Author: Sam Burdge

How to store and retreive arrays using cookies with php:

The first step is to turn the array into a string with each array value seperated by a delimiter. I usually choose an unusual delimiter character such as a vertical bar, as the array values are more likely to contain characters such as comma or slashes. Example:
Read on…

4 Responses to “cookies and arrays in php”

  • Comment by c-received
    Date: November 6th, 2007 at 9:54 pm

    Blend your own recipe….

    $a = array(’bg’=>’red’,'tx’=>’blue’,'lk’=>’green’);
    print_r($a);

    $b = implode(”|”,array(’red’,'blue’,'green’));
    print_r($b);

    $c = explode(”|”,$b);
    print_r($c);

  • Comment by kuberan marimuthu
    Date: September 20th, 2009 at 7:52 am

    this is an expensive solution. PHP cookies, itself supports storing arrays check this link http://www.developertutorials.com/tutorials/php/articlename-050526/page5.html

  • Comment by Steve
    Date: November 1st, 2010 at 8:58 am

    That is soooo inefficient. Use the serialize() function thus:
    setcookie(”myarray”, serialize($myArray), time()+3600);
    and to get data out:
    if(isset($_COOKIE['myarray'])) $myArray=unserialize($_COOKIE['myarray']);

  • Comment by Filip Gorczynski
    Date: November 24th, 2010 at 12:58 pm

    So, what do You think about sth like this:
    <?php
    if(isset($_COOKIE['c'])) {
    $a = unserialize($_COOKIE['c']);
    $a[] = time();
    setcookie(’c', serialize($a), time() + 1000);
    } else {
    setcookie(’c', serialize(array(time())), time() + 1000);
    }

Leave a Comment

welcome to my new site!!

Date: 18th October 2007 at 11:09 pm | Filed under: blog | Author: Sam Burdge

samburdge.co.uk is an online resource for web developers. It was set up by London-based web designer and video editor Sam Burdge, as a place to showcase new projects, and to share scripts, templates, and thoughts with the public.

Read on…

Leave a Comment

Info

Date: 3rd October 2007 at 3:07 am | Filed under: blog | Author: Sam Burdge

I'm Sam Burdge, a web designer and video editor from North London, UK. Currently I'm involved with two companies – 76 Creative, a web design studio for which I do the programming side of things, and Comus Productions, a digital video production company for which I edit programmes and provide technical back-up.

The purpose of this website is to showcase new projects I've been working on and to share my scripts, designs, ideas, and thoughts with the public. I welcome feedback about any posting on the site especially relating to code and development, but please refrain from leaving comments that promote or advertise services, products, events etc (all comments are moderated before they will be publicly visible on the site).

The WordPress theme for this blog, 76 Digital theme, is designed by myself and Alex Newman for 76 Creative. It comes in four colour schemes and is available to download {{post id="76-digital-wordpress-themes" text="here"}}.

If you have any comments or suggestions for the site please send them to:

Enjoy the site!

Leave a Comment

peoples studio

Date: 1st October 2007 at 11:44 pm | Filed under: portfolio | Author: Sam Burdge

Peoples Studio WebsitePeoples Studio Website MapPeoples Studio intro

The Peoples Studio website is built in flash backed up by php and xml scripts. It features an mp3 player, flash maps, contact forms for the different staff members and for showreel requests, and an animated intro. The site is powered by a bespoke CMS, which is built in php and allows the editing of every text-field in the entire site.

Original designs and layouts by Karl Wood for See Hear Speak.

Check out the site: www.peoplesstudio.co.uk

Leave a Comment