Oracle Apex: Get Client IP Address

Use the Owa_Util.Get_Cgi_Env() function with a parameter X-FORWARDED-FOR to get the client IP address in Oracle Apex. The following is an example:

Get Client IP Address in Oracle Apex

Execute the following SQL query from Oracle Apex SQL Workshop to test:

Select
    owa_util.get_cgi_env('X-FORWARDED-FOR')
From
    dual;

Below is an example of inserting a record in the table with values such as user id, date and IP address on logon in Oracle Apex.

Create a Table

Create Table login_detail (
    user_id          Varchar2(50),
    login_datetime   Date,
    ip_address       Varchar2(50)
)
/

Create a Process on Login Page (9999)

Create a PL/SQL code process on the login page (9999), after the Login process to get the client IP address and insert it into the above table:

Begin
    Insert Into login_detail (
        user_id,
        login_datetime,
        ip_address
    ) Values (
        :app_user,
        Sysdate,
        owa_util.get_cgi_env('X-FORWARDED-FOR')
    );

Exception
    When Others Then
        Null;
End;

Now, whenever the user will login, his user id, date and time of login and the IP address will be saved into the login_detail table.

The following is the screenshot for your reference:

Oracle Apex: Login Process.

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

5 Comments

  1. i got error while executing select statement for getting client ip address
    ORA-06502: PL/SQL: خطأ رقمي أو قيمة
    ORA-06512: عند "SYS.OWA_UTIL", line 354
    appreciate your support
    thank you

  2. Dear brother hope you are fine.
    I am in trouble to get client Mac Address when user login in apex.
    How can get client PC Mac? Please inform me by sending mail.

Comments are closed.