ACF Library

GetCookies

Back to List

Description: Get Cookie headers after HTTP request to use in subsequent requests

FileMaker Prototype:

Set Variable [$res; ACF_Run("GetCookies")]

Category: WEB

Function source:

function GetCookies ( )
    string line,keyValue ; 
    array string lines = explode ("\r\n", HTTP_HEADERS);
    array string cookieHeader;
    int i, x = sizeof(lines); 
   bool foundCookies = false; 
    for (i = 1, x)
        if (lower(left(lines[i], 11)) == "set-cookie:") then
            line = trimboth(right(lines[i], length(lines[i]) - 11)); 
            keyValue = left(line, pos( line,";")); // Extract key=value part before ";"
            cookieHeader[] = keyValue; 
         foundCookies = true; 
        end if
    end for
   if ( foundCookies ) then
       return "Cookie: " + implode("; ", cookieHeader);
   end if
   return ""; 
end

The GetCookies Function retrieves the Set-Cookie: lines from the HTTP headers after some HTTP_GET or HTTP_POST. Theese headers can be sent along with header parameter to subsequent requests.

Some API's use this to identify the session after authentication with the server. This can be used to identify the session in the next subsequent calls.

Example

Set Variable [$res; ACF_Run("GetCookies")]

Resulting in: 
Cookie: 4DSID_KK_xxV19=CF3634E36EEF48E1BB33A6510218DFA3; MY_V19=11684154_1YegDCC7f36CPi3

Just to be included in the headers for the next request.

Back to List