I would skip cookies and use the awesome script store.js
Just kick out a data-lightbox
attribute on the “Add to Lightbox” link with the image ID and (assuming you’re using jQuery) it’s this simple:
$( document.body ).on( "click", "a[data-lightbox]",
function ( ev ) {
ev.preventDefault();
var id = $( this ).data( "lightbox" ), list = store.get( "lightbox" );
if ( list ) {
if ( $.inArray( id, list ) === -1 )
list.push( id );
} else {
list = [ id ];
}
store.set( "lightbox", list );
}
);
And to download, just process the list & redirect to your server-side handler:
$( ".download" ).click(
function ( ev ) {
ev.preventDefault();
var list = store.get( "lightbox" );
if ( list ) {
var href = window.location.href,
args = ( href.indexOf( "?" ) !== -1 ? "&" : "?" ) + "download=" + list.join( "," );
window.location = href + args;
}
}
);
I’ve made the assumption that your handler accepts a comma-separated list of IDs in $_GET['download']
for any given URL.