# 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);  
begin  
  l\_ip := owa\_util.get\_cgi\_env('REMOTE\_ADDR');  
  htp.p(l\_ip);  
end;  
/  
  
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");  
   }  
   self.xmlHttpReq.open('GET', strURL, true);  
   self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
   self.xmlHttpReq.onreadystatechange = function() {  
       if (self.xmlHttpReq.readyState == 4) {  
           updatepage(self.xmlHttpReq.responseText);  
       }  
   }  
   self.xmlHttpReq.send(getquerystring());  
}  
  
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;  
}  
</script>  
  
<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>  
</form>   

  
  
  
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.
