The following link subscribes a user to your channel:
<a href="http://avantgo.com/channels/_add_channel.pl
?cha_id=xxxx &set_cookie=userID%3D58246%3B
path%3D/%3B
domain%3D.mywebsite.com%3B
expires%3DSat,+20+Feb+2010+01:31:52+GMT">Add AvantGo channel!</a>
Note: The above link is broken onto multiple lines for better readability. You should make your link all on one line. Including new lines within a quoted string can cause bad things to happen.
A quick analysis of this:
-
<a href="http://avantgo.com/channels/_add_channel.pl?cha_id=xxxx
This is the usual _add_channel.pl link described above. You should replace xxxx with the number of your channel that contains your real content.
-
&set_cookie=
This tells _add_channel.pl that you want to set a cookie with your channel.
-
userID%3D58246%3B path%3D/%3B domain%3D.mywebsite.com%3B expires%3DSat,+20+Feb+2010+01:31:52+GMT
These are various parameters set by your cookie. In this case, we are setting userID to 58246, path to / domain to .mywebsite.com and expires to February 20th, 2010. The first parameter, userID is the cookie name/value pair we have created especially for our channel. The path, domain, and expires parameters are standard cookie settings. Ask your local webmaster for more information on those.
Note: You may have noticed the expiration date is slightly different than the date format normally used for setting cookies in that you need spaces (or their URL-escaped equivalent) between the day, month, and year instead of dashes. Be careful! This only applies to the case above, not when you normally use a set-cookie HTTP header. If you really care about why this is the case, it is because the URL above is not passed directly to AvantGo sync servers. It is first processed through an Apache module which uses the official date standard (RFC 822) rather than the slightly-different Netscape Cookie date standard.
Notice that we had to replace all of our equals signs with their URL-escaped equivalent of %3D and our semicolons with the URL-escaped equivalent of %3B. This is so we do not confuse the set_cookie= link. Note that you will also want to replace any & or " or spaces you have in your cookie as well with their URL-escaped equivalents.
Character
|
URL equivalent
|
|
=
|
%3D
|
|
&
|
%26
|
|
"
|
%22
|
|
(space)
|
+ or %20
|
|
;
|
%3B
|
Although the URL works on most browsers without escaping the colon and comma in the cookie expiration date, it would not hurt to escape those as well.
As one last enhancement, I can also add a &debug=1 flag to my URL, which tells the AvantGo sync server to present me with some debug information, about the cookie. If your cookie is set properly, it will provide you with a list of all the setting associate with that cookie. If your cookie is not set properly, it will tell you why. Do not forget to remove this flag once you are done testing your cookie!
If you want to have more than one cookie name-value pair created, you need to create additional set_cookie arguments in your _add_channel.pl URL. In other words...
<a href="http://avantgo.com/channels/_add_channel.pl
?cha_id=xxxx
&set_cookie=userID%3D58246%3B
path%3D/%3B
domain%3D.mywebsite.com%3B
expires%3DSat,+20+Feb+2010+01:31:52+GMT
&set_cookie=icecreamflavor%3Dchocolatechip%3B
path%3D/%3B domain%3D.mywebsite.com%3B
expires%3DSat,+20+Feb+2010+01:31:52+GMT
&debug=1">Add AvantGo channel!</a>
...will create two cookies. One with userID = 58246, and another with icecreamflavor = chocolatechip. It also provides some debug information, telling you whether or not the cookie was set successfully. It will look something like this:
set_cookie 1: userID=58246;path=/; domain=.mywebsite.com; expires=Sat, 20 Feb 2010 01:31:52 GMT set_cookie 2: icecreamflavor=chocolatechip;path=/; domain=.mywebsite.com; expires=Sat, 20 Feb 2010 01:31:52 GMT Final cookie list for domains matching this channel:
2 COOKIES UPDATED SUCCESSFULLY. Cookie 1
name userID
value 58246
path /
domain .mywebsite.com secure flag 0 (SSL optional)
expires 1266629512 (Sat, 20 Feb 2010 01:31:52 GMT)
timestamp 956688969 (Tue, 25 Apr 2000 18:56:09 GMT) Cookie 2 name icecreamflavor value chocolatechip path / domain .mywebsite.com secure flag 0 (SSL optional) expires 1266629512 (Sat, 20 Feb 2010 01:31:52 GMT) timestamp 956688969 (Tue, 25 APR 2000 18:56:09 GMT)
|