Web Server Reference

*WEB/COOKIE

Set, Send and Retrieve Cookies

Description

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.

Note:
The internal variable %cookie.snd is incremented for each cookie you SET. Cookies are stored in strings in temporary variables as %cookie.nnn$ where nnn is the cookie number.

Format

*web/cookie EntryPoints

  1. Return:   EntryPoint =GET CALL "*web/cookie;GET",number,name$,data$
  2. Send:     EntryPoint =SET CALL "*web/cookie;SET",name$,data$,path$,expires$,domain$[,secure]

Where:

number

Ordinal number of the given cookie (Range: 1 to 300, Size Limit = 4K each).

Note:
The Web Server sets %cookie.rcv to the total number of cookies received or 0 (zero) for no cookies received.

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.

/sales/orders/ would match /sales/orders/myapp and /sales/orders but would not match /sales or /support/orders.

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.
domain$="proxy.pvxplus.com" is a cookie that is only valid for any path$ on the "proxy" machine 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:

=1 (one) if you only want the cookie returned when the connection is secure.

=0 (zero) otherwise. The value is 0 (zero) if you omit secure, as in the following:

Example:

CALL "*web/cookie;SET",name$,data$,path$,expires$,domain$

"expires$" Parameter

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$="19990709143030" (HH is in 24-hour time)

expires$="+nnnn" 

or
 

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:

expires$="
+1Y" sets an expiry 1 year from NOW
expires$="+30D" sets an expiry 30 days from NOW
expires$="+5H" sets an expiry 5 hours from NOW