PHP Configuration for HTTP Basic Proxy Authentication
ProxyMesh also supports IP address authentication, for which you do not need to use a username and password. Instead, set the
http_proxy environment variable to
For PHP configuration, you can use the included Client URL Library (cURL). To configure proxy settings, use the curl_setopt function to set
CURLOPT_PROXY to the proxy host and port, such as
PROXYHOST:PORT. Optionally, for authentication, you can set
USERNAME:PASSWORD. Note that, of these two,
CURLOPT_PROXYPWD is the better choice for HTTPS.
X-ProxyMesh-IP with HTTPS Requests
HTTPS requests with custom headers – such as
X-ProxyMesh-IP to specify an IP address – are difficult because the actual request headers are encrypted. With PHP, however, you can use
CURLOPT_PROXYHEADER to send the
X-ProxyMesh-IP header in PHP cURL. Use the following option:
CURLOPT_PROXYHEADER => [ 'X-ProxyMesh-IP: PROXYIP' ]
In this way, you should be able to request the same IP address at any time, assuming continued availability.
You can also use
CURLOPT_PROXYHEADER to pass in other custom headers from a linked list to HTTP or HTTPS requests. Click here for more information and a code example.
Passing Cookies to the Proxy
Cookies are passed as HTTP headers (such as X-ProxyMesh-IP or X-ProxyMesh-Prefer-IP), both in the request and in the response. The proxy servers do not modify them, and cookies are passed through unchanged. However, you may need to keep using the same proxy IP for your cookies to work correctly. Use code similar to the above example to pass in the
X-ProxyMesh-IPheader, in order to maintain the same IP. This should work with both http and https.
Chaining Proxies in PHP
Some queries are blocked by server security tools that apply learned blocking information automatically on all servers enabled for them. This can often be an issue for requests through the world proxy. However, it's important to avoid or bypass blocks if your use cases include avoidance of rate limits, high-traffic operations, high anonymity, or screen scraping.
If you are on a shared hosting service, installing VPN is not an available workaround for blocking. The X-ProxyMesh-Country header can be a useful workaround unless you are connecting to an HTTPS site, in which case you need special handling to pass the header in. Details are provided in Proxy Server Requests over HTTPS.
As a more consistently effective workaround, consider proxy chaining. With this approach, you connect to proxies in sequential steps until you reach your intended destination.
Below is a sample of code for a PHP connector client based on web sockets. Please also see the proxy_chain.php example in the PHP WebSocket2 Library.
Please Note: The code sample below is for the HTTP protocol only. At this time we do not support the SOCKS protocol.
$proxy1 = new HttpProxy(' world.proxymesh.com', 31280);
$proxy1 = new HttpProxy(' us.proxymesh.com', 31280);
$proxy1->setAuth(' PROXY-USER ', 'xxxxxx');
$webResponse = $proxy1->sendRequest($request);