Programming Guide |
Sets HTML cookies on a client
#include <smuweb.h>void sm_web_set_cookie(char *cookie_string);
cookie_string
- Specifies the cookie's name and properties in the following format:
cookie-name=value
[ ;
expires=date
] [ ;
path=path-string
]
domain=
[ ;domain-name
] [ ; secure ]
name
=value
- Specifies a unique character string to identify the cookie and assigns the cookie a value. For example:
Visits=1expires
=date
- Specifies an expiration date for the cookie in Greenwich mean time (GMT), where
date
has this format:Wdy, DD-Mon-YYYY HH:mm:ss GMT
After this date, the cookie is no longer stored or given out. This parameter must be specified in order to store the cookie value on the browser for multiple sessions; otherwise, the cookie value expires when the browser session ends.
For example, the following cookie expires on December 31, 1999 at 11:45 PM.
Friday, 31-Dec-1999 23:45:05 GMTpath=
path
- Specifies the path of the URL to use in matching the cookie values. If you specify the path value as
/
, the cookie is sent for every request to your HTTP server. If you specify the path value as/
dir
, the cookie is sent only if the URL path contains/
dir
. For example,path
might be set as follows:path=/vidGiven this path, the cookie is included when the following URL is sent to the HTTP server:
http:/www.Panther.com/cgi-bin/vid/main.scrdomain=
domain-name
- Specifies the domain of the URL to use when matching the cookie values. If there is a tail match, the path value is checked to determine whether to send the cookie value.
The value specified must have at least two periods in it. For example:
domain=.Panther.comsecure
- Specifies to send the cookie only if the HTTP request is transmitted to a secure server.
Web
sm_web_set_cookie
adds the specified string to a list of cookies. When HTML is generated for the screen, each cookie is sent as aSet-cookie:
header. After HTML generation, the list of cookies is removed.Cookies are pieces of information that can be stored on the browser side of the connection and later retrieved. In order to use them, the browser must accept cookie specifications.
Any cookie specified with this function is included in the HTML header for the screen. If accepted by the browser, the cookie is stored on the browser. Afterward, if the browser asks for a resource from the HTTP server that originally sent the cookie, the cookie value is sent along with the resource request.
// Get the browser's cookie values for user and visit_num
// and insert those values into the user and visit_num
// fields on the screen, then reset the visit_num cookie
// to its new value.
proc entry
user = sm_web_get_cookie("user")
visit_num = sm_web_get_cookie("visit_num")
visit_num = visit_num + 1
call sm_web_set_cookie("visit_num=:visit_num;\
expires=Monday, 03-Jan-2030 00::00::00 GMT; \
domain=.Panther.com; path=/samples")