Friday, February 02, 2007

Oracle Portal Client IP Address (REMOTE_ADDR)

You may want to show the IP address of the client (the browser) on a Portal page. This can be tough because the page is built by the parallel page engine (PPE). At that point, the actual requestor is the mid-tier itself. You need to make a call that goes all the way to the database without being redirected through the PPE. I do this by creating a pl/sql procedure (ideally part of a package) that I then call from a bit of javascript in the page (possibly through a UI Temple / HTML Template). Note: if the user is going through a proxy you will get the proxy IP. If you have a reverse proxy setup (e.g. multiple Oracle Web Caches or Apache Reverse Proxy) you can set things up to get the correct browser IP. See my other post on setting up chained Web Caches.

Here is the procedure, it's fairly straightforward.

CREATE OR REPLACE procedure c2_getClientIP is
l_ip varchar2(200);
l_ip := owa_util.get_cgi_env('REMOTE_ADDR');

grant execute on c2_getClientIP to public;

Then you put a little javascript in the page to call that procedure.

<script language="Javascript">
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}'GET', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {

function getquerystring() {
var form = document.forms['f1'];
var word = form.word.value;
qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
return qstr;

function updatepage(str){
document.getElementById("result").innerHTML = str;

<form name="f1">
word: <input name="word" type="text"> <input value="Go" type="button" onclick='JavaScript:xmlhttpPost("/pls/portal/portal.c2_getClientIP")'>
<div id="result"></div>

You can put the javascript in a template or as a text item. You can modify this however you want to either just show the IP, put in a variable, etc.


Anonymous said...

Just saying "Howdy" ... Jason Bennett

Neelesh said...


Paul said...

looks like the code got chopped??

Anton Nielsen said...

Sorry Paul, it's the blog template. If you just copy and paste it in to an editor it will all be there.


GeneraL aFiFy said...

Very Helping ...
Thank you very much

Anonymous said...

I am sorry, but I don't see where the PL/SQL procedure c2_getClientIP is being called in the Javascript code. Could you please explain this?

Anton Nielsen said...

Copy and paste the code into an editor. The template cuts off the code. I am pasting it below as well.


dynamic said...

Hi ,

Nice Document For Portal.

Current I try to configuration validation client ip on portal 3.0.

Our Environment match with your following scenario.

Scenario 2: Oracle Web Cache in the DMZ (WC1) acting as a Reverse Proxy to another Web Cache that serves your content (WC2). It looks like this:

Browser ---> WC1 ---> WC2 ---> Apache ---> mod/plsql ---> Database


So As Per your Artical setting implement url_cookie_ip_check does not work.

We enable this setting, it impact our Middle War Oracle App Server went down during busiest hours.

Is any idea for setting up this functionality in Portal.


Anton Nielsen said...

As mentioned in the document you reference:

You need to set url_cookie_ip_check = 'N'. This should solve your problem.


Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Hi Anton,

Do you have an e-mail to send you some info about my problem regarding the Oracle Client IP Address?

Anton Nielsen said...


If you are looking for consulting the best way to get me is to click the C2 Consulting link in the headers and leave call or leave a note there. You can send me a specific email if you want; I'm anton.nielsen at the company url listed in th link above. The most helpful thing would be the error message that you get in the error log (from the 404 error you mention): $ORACLE_HOME/Apache/Apache/logs/[most recent error log]