For each click while the session hasn't timed out, you need to update the cookie to push the expiration time again.
create or replace package cookie is
procedure main_page;
end cookie;
/
create or replace package body cookie is
function get_cookie
(v_cookie_name in varchar2) return varchar2 is
v_cookie_val owa_cookie.cookie;
begin
v_cookie_val := owa_cookie.get(v_cookie_name);
if v_cookie_val.Num_vals > 0 then
return(v_cookie_val.vals(1));
else
return('zero');
end if;
-- htp.print('GOT COOKIE');
end get_cookie;
procedure set_cookie (v_cookie_name in varchar2,
v_cookie_val in varchar2) is
begin
owa_util.Mime_header('text/html',FALSE);
owa_cookie.send(v_cookie_name,v_cookie_val);
owa_util.http_header_close;
-- htp.print('COOKIE SENT');
End Set_cookie;
procedure main_page is
v_cookie varchar2(15);
Begin
v_cookie := get_cookie('COUNT');
IF v_cookie = 'zero' THEN
set_cookie('COUNT',1);
ELSE set_cookie('COUNT',to_number(v_cookie)+1);
END IF;
htp.htmlopen;
htp.bodyopen;
htp.center('Our cookie indicates that you have' || v_cookie);
htp.bodyclose;
htp.htmlclose;
end main_page;
end cookie;
/
create or replace package cookie_pack
is
procedure send;
procedure get;
procedure kill;
end cookie_pack;
/
create or replace package body cookie_pack
is
procedure send
is
seq_val number := 0;
the_cookie owa_cookie.cookie;
session_name varchar2(4096) := '';
begin
the_cookie.num_vals := 0;
the_cookie := owa_cookie.get('SESSION');
if the_cookie.num_vals = 0 then
select sess_seq.nextval
into seq_val
from sys.dual;
-- the mime header command sends a command to the user's browser
-- indicationg that the information to follow is a new HTTP request.
-- The cookie commands must be the first command in the header.
owa_util.mime_header('text/html', FALSE);
session_name := 'Session is ' || seq_val;
-- The cookie send will send the following to the HTML
-- Set-Cookie: <name>=<value> expires=<expires> path=<path> domain=<domain> secure
owa_cookie.send('Session', session_name, NULL, '/', NULL, NULL);
owa_util.http_header_close;
end if;
htp.htmlOpen;
htp.headOpen;
htp.title('Cookie Example - Send');
htp.headClose;
htp.bodyOpen('/image/owasbkg','bgcolor=white');
htp.header(1, 'Cookie Example - Send');
htp.CenterOpen;
htp.fontOpen(NULL,'arial','+1');
htp.print('Send Cookie Page');
htp.fontclose;
if the_cookie.num_vals= 0 then
htp.header(3,'Setting cookie' || htf.fontopen('blue')||'SESSION'||htf.fontclose||
' = ' ||htf.fontopen('red')||session_name||htf.font_close);
else
htp.header(3,'Setting cookie' || htf.fontopen('blue')||'SESSION'||htf.fontclose||
' = ' ||htf.fontopen('red')||session_name||htf.font_close||'Already Set');
end if;
htp.centerclose;
htp.blockquoteOpen;
htp.preOpen;
htp.bold('Send A Cookie:');
htp.print ('owa_util.mime_header(''text/html'',false); ');
htp.print ('session_name := Session_' || seq_val );