tags:

views:

302

answers:

3

hi, i am using curl to get some info from a website, however it uses the server ip address but i want it to use the client ip address, so each user send request with their own ip not the servers, how is that possible?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "URL");
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$buffer = curl_exec($ch);
curl_close($ch);
+1  A: 

Heh, that's not possible. You can't use somebody else's IP address as the originating address for calls (except if you're misusing them as a Proxy, or spoofing addresses, of course).

If you elaborate what you want to achieve, maybe somebody comes up with a workaround.

Pekka
My situation is that a user submits an url and it gathers some info from that website, all im trying to do is i want the curl to use the users ip not the servers. is it possible with the methods you mentioned (proxy or spoofing). can curl use the user ip as proxy?
Joe
Nope, it's not possible. Spoofing is what blowdart describes in the second paragraph of his answer, and you can't use the user as a Proxy (fortunately). If you want your user to fetch data, you'll need to install an application on their computer. Why do you need the user's IP anyway? This sounds fishy.
Pekka
cause the website suspends the ip for a temporary time if too many people connect at the same time but if curl could use the users ip, then this wont happen
Joe
I see. Sorry, you won't get around this - it's too close to illegitimate uses like hijacking users' computers for malicious purposes. You would have to install an application on the user's computer, *or* use some Flash or Java - but even thouse could fail doing it due to cross domain policies.
Pekka
If there's a per-IP rate limit, you can always have a range of IPs assigned to your server, and explicitly bind to them. But you'd have to run that by the maintainers of the service -- if they don't approve, they'll just ban you anyway.
Frank Farmer
+2  A: 

It's not. The server IP is sent because the website you're looking at needs to know where to send the data back again.

If you ended up faking the IP, which is something CURL is not capable of (you need something that manipulates raw packets/sockets) then your code would never see the reply.

blowdart
Key takeaway, "your code would never see the reply".
Mr-sk
A: 

PHP does not run on the client's machine. Any network connections done via PHP will be done with your web server as the connecting client. It may help if you conceptualize it like this: when a client accesses your PHP page, PHP executes on your server and generates an HTML page. It is that generated HTML page that is sent over the network to the client, not any of your PHP code. PHP is just a tool for dynamically generating HTML pages.

The only solution I see is to dynamically alter an iframe's URL then use javascript to parse through the iframe's contents. If you want information delivered back to you, you can use AJAX routines to connect back and deliver any information your javascript gathered from the iframe.

jdizzle