The CURLOPT_PROXY
sets the IP of the proxy you want to use. The proxy can be http
(pattern), socks4
or socks5
.
This is indicated in the documentation: https://curl.se/libcurl/c/CURLOPT_PROXY.html.
You cannot set any IP arbitrarily, after all, you want to also get the answer. Technically, you can forge Ips on TCP, but you won’t be able to get any results. Anyway, the CURLOPT_PROXY
does not have that purpose, the CURLOPT_PROXY
nay forge/change TCP packets to another arbitrary IP.
The CURLOPT_PROXY
establishes a connection to a proxy server, it will forward your request. At the end, the final server (Google) will see the proxy IP (and will not see your real IP).
You must purchase proxies (search Google for "buy proxies"). There are several different types of proxies, you should find one that best fits your use case. Alternatively, you can create your own proxy as long as you have multiple Ips... Just set up a proxy server (like Squid Proxy Server) and then it will switch between the Ips you have. But again, you need to acquire Ips, and those Ips will be the ones that Google will see. The difference is, you can have a single server, and multiple outgoing Ips.
You can also try using free proxies (search for "free proxies") and get something like http://www.freeproxylists.net. Or, you can also choose to use Tor or I2P.
To test, you can request https://api.myip.com
(instead of google) to see your IP. If the request via Curl has a different IP than your device, then the proxy is configured correctly.
Obviously, public (and free) proxies are used by anyone and may not solve your problem. After all, other people are using them to request Google.
Once you have the proxy IP you want to use specify it in CURLOPT_PROXY
. Also, remove the CURLOPT_PROXYTYPE
, or define it properly.
To see what error is occurring with your request, add a echo curl_error($ch)
.