如何在php中发送http请求时设置代理而不是真正的IP? [关闭]

I want to hide my real IP while sending any http request in php. what should I do, is it possible? if not, is there any way to do it excepts PHP?

When the server receives a request, it needs to be able to send a reply back to the client. It knows where to send that reply back because it knows the IP address of the client. You cannot establish an HTTP (or, more generally, TCP) session with a spoofed IP address.

At the IP level, you can send an IP packet with a spoofed source address. That's not going to do much good to connect to a web server though. If the packet isn't a TCP packet sent to port 80 on the server, it's probably not even going to reach the server, it's likely to be blocked by a firewall that's between the server and the Internet.

As soon as you want to establish a TCP connection, the connection starts with the client sending a packet to establish the connection, and the server replies. Until the client has obtained a reply from the server, the connection is not established, and if the client tried to fake subsequent packets, they would probably be blocked by the server-side firewall. With the PHP curl library, you can only make well-formed TCP connections anyway.

Since the server needs to know what IP address the requests come from in order to be able to send back replies, the only way to fake your IP address is to cause these requests to come from a different machine. That is, if you want your IP address to appear to be $ip1, you need to get the machine with the address $ip1 to relay your requests. In other words, you need $ip1 to act as a proxy.

Reference: https://security.stackexchange.com/questions/26310/how-can-i-spoof-my-ip-address-using-the-php-curl-function