MattsBits
MattsBits

MattsBits

Using Oracle PLSQL To Create, Delete And View Cookies  

by Matt Hawkins, 09/09/2010
Categories : Oracle

You can create, delete and view browser cookies within PLSQL using an Oracle Web Agent (OWA) package called "owa_cookie".

This package can be used within APEX if required.

BEGIN
 
   owa_util.mime_header('text/html', FALSE);
   
   -- Create a cookie
   owa_cookie.send(
      name=>'MyCookie1',
      value=>'value1',
      expires=> sysdate+1,
      path=>'/');
 
   -- This cookie specifies a domain
   owa_cookie.send(
      name=>'MyCookie2',
      value=>'value2',
      expires=> sysdate+1,
      path=>'/',
      domain=>'example.com');
 
   owa_util.http_header_close;
 
EXCEPTION
   WHEN OTHERS THEN NULL;
 
END;


If you don't specify an expire date the cookie will only exist for the life of the current session.


To delete a cookie you can use :

owa_cookie.remove(
      name=>'MyCookie1',
      value=>NULL);


This procedure forces a cookie to expire immediately by setting the "expires" field of a Set-Cookie line in the HTTP header to "01-Jan-1990".

To read a value from a cookie you can use the owa_cookie.get function :

DECLARE

  MyCookie OWA_COOKIE.COOKIE;
  MyValue  VARCHAR2(50);
  
BEGIN

  -- Read cookie into cookie record
  MyCookie := OWA_COOKIE.GET('MyCookie1');
  
  -- Extract value from cookie record
  MyValue  := MyCookie.VALS(1); 

END;

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2017