function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VyadiVyadi 

Trying to get user IP

Hi All,

             I am trying to get the user ip from salesforce and I am using something like

String strIpAdd = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');

 

to get it. However I am getting a null pointer exception. My guess is I am not getting the header from the VF page. I am not sure why this is happening. Would appreciate some input on this.

 

Thanks.

b-Forceb-Force

public class IP
{

public String ip { get; set; }

public IP()
{
ip= ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
}
}

 

This code snippet works fine for me . Please check http://boards.developerforce.com/t5/Visualforce-Development/HTTP-Header-Values-for-client-IP-Address/td-p/138115 for more clarification

 

Thanks,

bForce

upperupper
Here is my snippet. you can use it to test the differences

public class IP
{
    public String p1 { get; set; }
    public String p2 { get; set; }
    public String p3 { get; set; }
    public String getIp1() {
        p1= ApexPages.currentPage().getHeaders().get('True-Client-IP');
        return p1;
    }
    public String getIp2() {
        p2= ApexPages.currentPage().getHeaders().get('X-Forwarded-For');
        return p2;
    }
    public String getIp3() {
        p3= ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
        return p3;
    }
}