<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[xajax Forums - Modify xajax to set cookie]]></title>
	<link rel="self" href="http://community.xajaxproject.org/feed/atom/topic/5953/"/>
	<updated>2007-11-04T12:13:11Z</updated>
	<generator>PunBB</generator>
	<id>http://community.xajaxproject.org/topic/5953/modify-xajax-to-set-cookie/</id>
		<entry>
			<title type="html"><![CDATA[Re: Modify xajax to set cookie]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/21934/#p21934"/>
			<content type="html"><![CDATA[Could it be useful when we want to set a cookie on the client from a field which is not created as part of a form, nor part of a call which is to be communicated back to the server :
xajax_something( $too, $many, $vars, $already)

I was going to do this as a "setting" or "state" set up on the client, which is picked up on the server with $_COOKIE ?

So you might have a checkbox say: "[ x ] display postal codes " that dictated whether that info should be displayed from now on.  Nothing needs to be sent server side just yet ...

Maybe there is another way of doing this, as a serious noob, I would guess that there probably is - but setting a cookie is something I am just about to write client side now - for the above reasons.

So ( in my igonorance, as I have pointed out already )  I'd agree with the OP.  some generic cookie setting code might be a nice idea.]]></content>
			<author>
				<name><![CDATA[Yossarian]]></name>
				<uri>http://community.xajaxproject.org/user/2361/</uri>
			</author>
			<updated>2007-11-04T12:13:11Z</updated>
			<id>http://community.xajaxproject.org/post/21934/#p21934</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Modify xajax to set cookie]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/21912/#p21912"/>
			<content type="html"><![CDATA[erm, I can't see any benefit from setting the cookie via JavaScript. [url=http://php.net/manual/en/function.setcookie.php]setcookie[/url] works fine...]]></content>
			<author>
				<name><![CDATA[q_no]]></name>
				<uri>http://community.xajaxproject.org/user/569/</uri>
			</author>
			<updated>2007-10-31T17:27:09Z</updated>
			<id>http://community.xajaxproject.org/post/21912/#p21912</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Modify xajax to set cookie]]></title>
			<link rel="alternate" href="http://community.xajaxproject.org/post/21911/#p21911"/>
			<content type="html"><![CDATA[xajax.js


this.createCookie=function(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+"; path=/";}    
this.readCookie=function(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);} return null;}
this.eraseCookie=function(name){this.createCookie(name,"",-1);}


xajaxResponse.inc.php
    function setCookie($cname,$cval,$cexp)
    {
        $this->xml .= $this->_cmdXML(array("n"=>"sc","t"=>$cname,"p"=>$cexp),$cval);
    }
    
    // eraseCookie($cname)
    function eraseCookie($cname)
    {
        $this->xml .= $this->_cmdXML(array("n"=>"ec"),$cname);
    }]]></content>
			<author>
				<name><![CDATA[gamlet]]></name>
				<uri>http://community.xajaxproject.org/user/2355/</uri>
			</author>
			<updated>2007-10-31T16:41:28Z</updated>
			<id>http://community.xajaxproject.org/post/21911/#p21911</id>
		</entry>
</feed>
