Home » Developer & Programmer » Application Express, ORDS & MOD_PLSQL » User's IP address (APEX,oracle xe,xp)
User's IP address [message #347539] Fri, 12 September 2008 01:06 Go to next message
andi_raj
Messages: 55
Registered: February 2008
Member
We have developed a software using apex. We are able to store the user's name and timestamp when he logsin in a table. Is it possible to store the user's PC IP address or computer name so that it will be possible to know from which PC the user has logged in. Thanks in advance.
Re: User's IP address [message #348457 is a reply to message #347539] Tue, 16 September 2008 16:44 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Just make a call to OWA_UTIL.get_cgi_env ('REMOTE_ADDR'). You can include it directly in a SQL statement.

Getting the username is more difficult. Search here http://forums.oracle.com/forums/forum.jspa?forumID=137

[Updated on: Tue, 16 September 2008 16:45]

Report message to a moderator

Re: User's IP address [message #348509 is a reply to message #348457] Wed, 17 September 2008 01:18 Go to previous messageGo to next message
andi_raj
Messages: 55
Registered: February 2008
Member
Thank you for the reply.
I am only getting 127.0.0.1 which is the local host address.
is it necessary to give grant for running this sql? I want the machine IP address and not local host.
Re: User's IP address [message #348665 is a reply to message #348509] Wed, 17 September 2008 09:11 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
It sounds like you are running the test from your own machine - try from another machine. I use this successfully.
Re: User's IP address [message #350806 is a reply to message #347539] Fri, 26 September 2008 07:55 Go to previous messageGo to next message
zraz
Messages: 20
Registered: September 2008
Location: Poland
Junior Member
Hello,

how can I use this code in APEX in the first page:
DECLARE
i NUMBER := 2;
v_ip varchar2(25):='127.0.0.0';
BEGIN
IF OWA.num_cgi_vars IS NOT NULL
THEN
v_ip := OWA_UTIL.get_cgi_env ('REMOTE_ADDR');
ELSE
v_ip := SYS_CONTEXT ('USERENV', 'IP_ADDRESS');
END IF;
END;

I added this as ITEMS / DISPLAY ONLY but i doesn't show any IP address.
Re: User's IP address [message #350835 is a reply to message #350806] Fri, 26 September 2008 11:15 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Simple example:
Add region "PL/SQL Dynamic Content"
Set PL/SQL Source:
htp.p(OWA_UTIL.get_cgi_env ('REMOTE_ADDR'));
Re: User's IP address [message #351382 is a reply to message #350835] Tue, 30 September 2008 10:14 Go to previous messageGo to next message
zraz
Messages: 20
Registered: September 2008
Location: Poland
Junior Member
Hi,

thank you for good response, it works.
I want to get also an username of Windows.
It is possible ?
Re: User's IP address [message #351405 is a reply to message #347539] Tue, 30 September 2008 12:46 Go to previous messageGo to next message
zraz
Messages: 20
Registered: September 2008
Location: Poland
Junior Member
andi_raj wrote on Fri, 12 September 2008 08:06
We have developed a software using apex. We are able to store the user's name and timestamp when he logsin in a table. Is it possible to store the user's PC IP address or computer name so that it will be possible to know from which PC the user has logged in. Thanks in advance.


How did you get user's name from PC ?. Can you write an sample code ?.

Thanks in advance
Re: User's IP address [message #352130 is a reply to message #351405] Mon, 06 October 2008 05:00 Go to previous messageGo to next message
andi_raj
Messages: 55
Registered: February 2008
Member
select sys_context('USERENV', 'OS_USER') from dual;
hope this helps.
raj
Re: User's IP address [message #352158 is a reply to message #352130] Mon, 06 October 2008 06:29 Go to previous message
zraz
Messages: 20
Registered: September 2008
Location: Poland
Junior Member
Hello,

when i uset it in SQL*Plus as:
select sys_context('USERENV', 'OS_USER') from dual;
it works but as PL/SQL:
declare
usern varchar2(29);
begin
select sys_context('USERENV', 'OS_USER') into usern from dual;
dbms_output.put_line('User_win: '||usern);
end;
/

it returns username that login to SQL*Plus.
What is the problem ?.

[Updated on: Mon, 06 October 2008 06:29]

Report message to a moderator

Previous Topic: oraclexe, apex 3.1
Next Topic: Query Process Help
Goto Forum:
  


Current Time: Thu Apr 18 13:27:02 CDT 2024