0

I've set up an ajax script with jQuery to have a user subscribe to a mailing list.

Is there a way I can send the subscriber's REMOTE_ADDR in curl? Right now it's posting the IP_ADDRESS as the address of the server, but I need to capture the subscriber's ip.

I'm not trying to spoof anything, I just need to find a way to make sure I'm getting accurate information for email marketing compliance.

I tried adding the following to the curl post:

$ip = $_SERVER['REMOTE_ADDR'];

$ipaddress = array(
    "REMOTE_ADDR: $ip",
    "HTTP_X_FORWARDED_FOR: $ip"
);          

curl_setopt( $ch, CURLOPT_HTTPHEADER, $ip_address);

but I'm still getting the server ip.

secondman
  • 3,233
  • 6
  • 43
  • 66
  • I don't think you can just change your IP address sent in the header like this. First, this would be a bit too easy to misuse. Second, the server would then not send the answer to your request back to you, but to the user's IP, or am I wrong here? – TheWolf Oct 09 '13 at 22:37

1 Answers1

1

Most of data from $_SERVER['REMOTE_ADDR'] is not real. for more information see https://stackoverflow.com/a/6794901/2855673

You must check all headers by php. Many open libraries do this. just search and get your fave code. like: https://gist.github.com/cballou/2201933

Community
  • 1
  • 1
saeedhbi
  • 350
  • 4
  • 17
  • So how can I post information to a remote server with PHP and keep the user's IP intact? – secondman Oct 10 '13 at 06:09
  • Decided to use JSONP instead, thanks though, your answer was good. – secondman Oct 10 '13 at 08:46
  • Yea, you can get ip address with JSON. Use http://jsonip.appspot.com/ appspot for these. for example: $.getJSON("http://jsonip.appspot.com?callback=?", function(data){ alert( "Your ip: " + data.ip); }); This is for alert user IP. change these as yours. – saeedhbi Oct 10 '13 at 11:33