UDT to set multiple cookies

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
kendo451

UDT to set multiple cookies

Post by kendo451 »

I wrote this User Defined Tag (UDT) to set multiple cookies.  I saved it as "setCookies" in the site's UDT section.

Use it like this in the page:

{setCookies days='numDays' cookie1="value1" cookie2="value2"}

Required Parameters:

days='5'  this sets the expiration date of the cookie.

This will work with versions of CMSMS that process the body before the head of the document. (Cookies must be sent before the . So if you have it set up that CMSMS processes the head before the body, where your {setCookies} tag is, then it will not work.)

You can have as many cookie="value" pairs as you want, with any name you want, as long as each cookie name is unique.

Here's the code:

Code: Select all

if (isset($params)) {

    if (isset($params['days'])) {
        $expire=time() + ($params['days']*86400);
        
        foreach ($params as $name => $value) {
            if ($name!='days') {
                setcookie($name,$value,$expire); 
                unset($value);
                }
            }
        return;
        }
    else {
    	print('Error: setCookies parameter "days" is required');
    	}
    }

else {
    print('Error: setCookies requires parameters.');
    return;
    }
User avatar
mozart_ar
New Member
New Member
Posts: 8
Joined: Fri May 22, 2009 7:53 pm

Re: UDT to set multiple cookies

Post by mozart_ar »

Thanks!  ;)
Post Reply

Return to “Tips and Tricks”