Skip to content

Instantly share code, notes, and snippets.

@chobie
Created October 4, 2010 09:34
Show Gist options
  • Save chobie/609451 to your computer and use it in GitHub Desktop.
Save chobie/609451 to your computer and use it in GitHub Desktop.
<?php
//simple http proxy connection sample
$proxy = "proxy.example.com";
$port = 8080;
$url = "https://example.com/";
$host = parse_url($url);
$fp = fsockopen("tcp://" . $proxy, $port);
$request = "GET $url HTTP/1.1\r\n";
$request .= "Host: {$host['host']}\r\n";
$request .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$request .= "Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n";
$request .= "Accept-Encoding: gzip,deflate\r\n";
$request .= "Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n";
$request .= "User-Agent: Your/User-Agent/1.0\r\n";
$request .= "Keep-Alive: 300\r\n";
$request .= "Proxy-Connection: keep-alive\r\n";
$request .= "\r\n";
fputs($fp, $request);
while(!feof($fp)){
$line = fgets($fp, 8192);
print($line);
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment