Secure Static IP for PHP HTTPS using QuotaGuard Shield

Learn how to securely route native PHP HTTP traffic through a QuotaGuard Shield proxy. Includes full code examples and Dockerfile.

Prerequisites

This only requires curl, which generally is installed alongside PHP.

Instructions

Run example
QUOTAGUARDSHIELD_URL=... php https.php
Test in Docker
docker build -t qg-shield-php-https-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-php-https-example

Code Samples

HTTPS.php
<?php

function lookup(){
  $quotaguard_env = getenv("QUOTAGUARDSHIELD_URL");
  $quotaguard = parse_url($quotaguard_env);

  $proxyUrl  = $quotaguard['host'].":".$quotaguard['port'];
  $proxyAuth = $quotaguard['user'].":".$quotaguard['pass'];

  $url = "https://ip.quotaguard.com/";

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
  curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
  $response = curl_exec($ch);
  return $response;
}

$res = lookup();
print_r($res);

?>
Docker File
FROM php:latest

COPY https.php /app/https.php

WORKDIR /app/

ENTRYPOINT [ "php", "https.php" ]