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
X-ProxyMesh-IPto specify an IP address – are difficult because the actual request headers are encrypted. With PHP, however, you can use
CURLOPT_PROXYHEADERto send the
X-ProxyMesh-IPheader 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.
Passing Cookies to the Proxy
Cookies are passed as HTTP headers, 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-IP header, 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.
$proxy1 = new HttpProxy(' <u>world.proxymesh.com</u>', 31280);<br> $proxy1->setAuth('PROXY-USER', 'xxxxxx'); <br> $proxy1 = new HttpProxy(' <u>us.proxymesh.com</u>', 31280);<br> $proxy1->setAuth(' PROXY-USER ', 'xxxxxx'); <br> $proxy2->setSocket($proxy1); <br> $proxy1->setSocket($socket); <br> $webResponse = $proxy1->sendRequest($request);
Do you want to work on the Laravel Project through the proxy? Laravel is a PHP-based framework for webpage development, popular among users with good skills in PHP and object-oriented programming. You can configure the proxy by following the steps in this article.