PHP code example of cnerta / behind-a-proxy-bundle
1. Go to this page and download the library: Download cnerta/behind-a-proxy-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cnerta / behind-a-proxy-bundle example snippets
// in AppKernel::registerBundles()
$bundles = array(
// ...
new Cnerta\BehindAProxyBundle\CnertaBehindAProxyBundle(),
// ...
);
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
//...
$s = curl_init();
curl_setopt($s, CURLOPT_BINARYTRANSFER, true);
curl_setopt($s, CURLOPT_FAILONERROR, true);
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_URL, $this->url);
// Call cnerta.baproxy service and call the method setProxyForCURL
// the CURL resource '$s' is passed by reference
$container->get('cnerta.baproxy')->setProxyForCURL($s);
curl_exec($s);
$status = curl_getinfo($s, CURLINFO_HTTP_CODE);
$error = curl_error($s);
curl_close($s);
if ($status == 401) {
throw new \RuntimeException("Invalid Credencial to connect to WebService");
} else if ($status == 404) {
throw new \RuntimeException("Invalid URL to connect to WebService");
} elseif ($status != 200) {
throw new \RuntimeException($error);
}