Skip to content

Instantly share code, notes, and snippets.

@24HOURSMEDIA
Last active December 6, 2021 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 24HOURSMEDIA/c3d3dff3cc266b20131af31ef7db243b to your computer and use it in GitHub Desktop.
Save 24HOURSMEDIA/c3d3dff3cc266b20131af31ef7db243b to your computer and use it in GitHub Desktop.
Get contents through proxy using curl or guzzle - tested wit bestproxyandvpn.com
PROXY_USER=...
PROXY_PASS=....
PROXY_IP=185.XXX.XXX.XXX
PROXY_PORT=37257
{
"name": "24hoursmedia/proxy-test",
"require": {
"vlucas/phpdotenv": "^2.5",
"guzzlehttp/guzzle": "^6.3"
}
}
<?php
/**
* Request through a Best VPN proxy using curl
*/
require __DIR__ . '/../vendor/autoload.php';
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
$dotenv->load();
$PROXY_IP = getenv('PROXY_IP');
$PROXY_PORT = getenv('PROXY_PORT');
$PROXY_USER = getenv('PROXY_USER');
$PROXY_PASS = getenv('PROXY_PASS');
$url = 'https://manytools.org/http-html-text/http-request-headers/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PROXY, $PROXY_IP);
curl_setopt($ch, CURLOPT_PROXYPORT, $PROXY_PORT);
curl_setopt($ch, CURLOPT_PROXYUSERNAME, $PROXY_USER);
curl_setopt($ch, CURLOPT_PROXYPASSWORD, $PROXY_PASS);
$result = curl_exec($ch);
<?php
/**
* Request through a Best VPN proxy using guzzle
*/
require __DIR__ . '/../vendor/autoload.php';
use GuzzleHttp\Client;
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
$dotenv->load();
$PROXY_IP = getenv('PROXY_IP');
$PROXY_PORT = getenv('PROXY_PORT');
$PROXY_USER = getenv('PROXY_USER');
$PROXY_PASS = getenv('PROXY_PASS');
$url = 'https://manytools.org/http-html-text/http-request-headers/';
$proxyClient = new Client([
'proxy' => rawurlencode($PROXY_USER) . ':' . rawurlencode($PROXY_PASS) . '@' . $PROXY_IP . ':' . $PROXY_PORT,
'headers' => [
'User-Agent' => 'my simulated user agent'
]
]);
$result = $proxyClient->get($url)->getBody()->getContents();
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment