Oracle Apex: Get Client IP Address

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.

This Post Has 5 Comments

  1. Md. Quium Hossain

    IP not get this query in SQL Workshop and Oracle apex Application, How to Solved??

    1. Md. Quium Hossain

      Hi, Vinish Kapoor, How to get IP Address in Oracle Apex Application?

  2. ‪ahmed mohsen‬‏

    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

  3. Fraz

    Is there any way to get client OS user name?

  4. alauddin ahmed

    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.