WebCookieSet Function

Action

Sets a cookie in the cookie database. The optional arguments domain, path and secure not specified in the sCookie string are set to their appropriate default values by examining sUrl.

Include file

WebAPI.bdh

Syntax

WebCookieSet( in sCookie : string,
              in sUrl    : string,
              in nDocNum : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
sCookie Data of a Set-Cookie: response header.
sUrl String that specified the URL for which the cookie should be set.
nDocNum

If this parameter is not specified, the cookie is added to the cookie database immediatly.

By specifying this parameter the cookie becomes a delayed cookie. This means, it will not be added to the cookie database immediately, but only before the document (frame) with the given number of the following page is downloaded.

Example

const
  MAX_COOKIE_BUFFER := 4096;

dclrand
  rsCustNo     : RndStr("0123456789", 10..10);
  rsCookieName : RndStr("COOKIE", 6..12);

dcltrans
  transaction TWebCookie
  var
    sCookie: string(MAX_COOKIE_BUFFER);
  begin
    // Put randomized cookies into the cookie database
    sCookie := "CUSTOMER_NO=" + rsCustNo +
               "; path=/; expires=Wednesday, 09-Nov-99 23:12:40";
    WebCookieSet(sCookie, "http://standardhost/");

    // Put a cookie into the cookie database
    sCookie := rsCookieName + "=; path=/; secure";
    WebCookieSet(sCookie, "http://standardhost/");
    // Put a cookie with a random name into the cookie database
    sCookie := rsCookieName + "=; path=/; secure";
    WebCookieSet(sCookie, "http://standardhost/");

    // Put a cookie into the cookie database
    // after the frameset and the first frame has been downloaded
    WebCookieSet(sCookie, "http://standardhost/", 3);
    WebPageUrl("http://standardhost/"); // frameset with 5 frames
  end TWebCookie;

Sample scripts

WebMulti01.bdf

SilkEssential sample

Cookies.sep