Search: For:
Browsing Single Category
www.dbatoolz.com ORACLE DBA Forums Solutions › Topic Id: 1224 | Permalink

Parse base domain name using HTTP_HOST in MOD_PLSQL

Topic ID: 1224
Created By: 2006-NOV-13 13:21:30 [Vitaliy]
Updated By: 2006-NOV-13 13:21:30 []
Status: New
Severity: Normal
Read Only: No
4502
2006-NOV-13 13:21:30
Moderator
 
 
Registered On: Mar 2006
Total Posts: 267
                Parse base domain name using HTTP_HOST in MOD_PLSQL

SOLUTION
---------

HTTP_HOST can be obtained via owa_util.GET_CGI_ENV to be later parsed using
INSTR/SUBSTR such as follows:

SQL> create or replace function base_domain return varchar2
  2  is
  3     l_http_host varchar2(4000) := owa_util.GET_CGI_ENV('HTTP_HOST');
  4  begin
  5     return substr(l_http_host,instr(substr(l_http_host,1,instr(l_http_host,'.',-1)-1),'.',-1)+1);
  6  end base_domain;
  7  /

Function created.


You could then use base_domain() function to set cookies for the base level domain:

       owa_cookie.send(name => 'cookie_name',
                       value => 'cookie_value',
                       path => '/',
                       domain => base_domain);


TEST CASE
----------
SQL> create or replace function base_domain_test(p_full_domain in varchar2) return varchar2
  2  is
  3     l_http_host varchar2(4000) := p_full_domain;
  4  begin
  5     return substr(l_http_host,instr(substr(l_http_host,1,instr(l_http_host,'.',-1)-1),'.',-1)+1);
  6  end base_domain_test;
  7  /

Function created.


SQL> select base_domain_test('server-name.sub-sub.sub.domain.com') from dual;

BASE_DOMAIN_TEST('SERVER-NAME.SUB-SUB.SUB.DOMAIN.COM')
--------------------------------------------------------------------------------

domain.com

SQL> select base_domain_test('sub.sub.domain.com') from dual;

BASE_DOMAIN_TEST('SUB.SUB.DOMAIN.COM')
--------------------------------------------------------------------------------

domain.com

SQL> select base_domain_test('sub.domain.com') from dual;

BASE_DOMAIN_TEST('SUB.DOMAIN.COM')
--------------------------------------------------------------------------------

domain.com

SQL> select base_domain_test('domain.com') from dual;

BASE_DOMAIN_TEST('DOMAIN.COM')
--------------------------------------------------------------------------------

domain.com

SQL>