*WEB/COOKIE |
Set, Send and Retrieve Cookies |
The PxPlus Web Server *web/cookie utility can be used to SET and/or GET cookies. Each cookie is a VARIABLE=DATA pair with return characteristics (path to match, domain, expiry and secure). Although Web Server requests are separate and unrelated and cannot share variables or data on the server, you can get around this by using cookies to pass data and variables to the browser, which, in turn, can send that information back for different requests.
When you SET a cookie, it is included in the header, along with your data, and sent back to the browser. The return characteristics determine when or if the browser will return the cookie with a request. All cookie parameters are cleared when the task is complete.
Format 1: CALL "*web/cookie;GET",number,name$,data$
Use Format 1 to retrieve a cookie. Your CALL should include three arguments. You must pass the number of the cookie (1 to %cookie.rcv). The program will return the name$ and the data$.
Format 2: CALL "*web/cookie;SET",name$,data$,path$,expires$,domain$[,secure]
Use Format 2 to create and send a cookie. Your CALL should include five arguments. A sixth parameter can be set to make sure the TCP connection is secure.
|
name$ |
Name of the cookie |
|
data$ |
Data to send to the browser |
|
path$ |
Your file path criteria for matching the URL's path |
|
expires$ |
Cookie's expiry date and/or time |
|
domain$ |
Domain name of your web site |
|
secure |
Indicates if the cookie should only be sent on secure connections |
If the conditions warrant it, the browser will return the cookie to the server when your user requests specific web pages. For instance, you can use SET to assign the user's LOGIN ID/PASSWORD to a cookie so that the user only has to enter it once. With cookies, you can also create shopping cart style applications that "remember" the items and quantities chosen.
Each VARIABLE=DATA pair is 1 cookie. You can SET up to 300 cookies, each with a size limit of 4K. The browser will return as many as it believes match a given request.
*web/cookie EntryPoints
Where:
number |
Ordinal number of the given cookie (Range: 1 to 300, Size Limit = 4K each). Note: |
name$ |
Name of the cookie (like a variable name). |
data$ |
Data in the given cookie. |
path$ |
The minimum match you want with a file path before the cookie is sent back. (If no match is found, the cookie is not sent back from the browser.) The path$ should be followed by a trailing / (forward slash). Example: The / (forward slash) alone would match any URL on your Web site. |
expires$ |
expires$ is the date (and/or time) that the cookie will expire. See "expires$" Parameter below for a list of acceptable values you can assign. |
domain$ |
domain$ is the domain name for your host site. The cookie is only valid for the current domain/host. If domain$>"", then it must include a minimum of 2 periods. Example: domain$=".pvxplus.com" is a cookie that is valid for any path$ in the pvxplus.com domain. If domain$="", then the cookie will only be valid for the current browser session. It will be cleared if the user moves to another site. |
secure |
If you include this parameter, the cookie will only be returned if the TCP connection is secure. The Boolean values are: Example: CALL "*web/cookie;SET",name$,data$,path$,expires$,domain$ |
The table below lists valid values for the expires$ parameter in the *web/cookie;SET sub-routine.
If: |
Then: |
expires$="" |
No expiry date is sent and the cookie will expire at the end of the current browser session. |
expires$="0" |
The date/time equivalent of RIGHT NOW will be sent. |
expires$="YYYYMMDDHHMMSS" |
Expiry is set to a specific date. The date must be in the format YYYYMMDDHHMMSS. Example: |
expires$="+nnnn" |
The cookie will expire NOW plus or minus nnnn time units. The default time unit is seconds, but you can append an alpha code to change or override the current setting (Y = Years; D = Days; H = Hours; M = Minutes, S = Seconds). Example: |