Using a proxy URL
Posted: Fri Mar 16, 2012 4:27 am
Hi All
I need to send data from an intranet through a proxy url. I have the following code:
When i run this code I get:

But when i try the URL directly in the browser's address bar, it works fine. Any suggestions?
Thanks
Marinus
I need to send data from an intranet through a proxy url. I have the following code:
Code: Select all
<?php
function proxy_url($proxy_url)
{
$error_no = 0;
$error_string = "";
$proxy_name = 'proxy.co.za';
$proxy_port = 80;
$proxy_user = "username";
$proxy_pass = "password";
$proxy_cont = '';
$proxy_fp = fsockopen($proxy_name, $proxy_port,$error_no,$error_string);
if (!$proxy_fp) {return false;}
fputs($proxy_fp, "GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n");
fputs($proxy_fp, "Proxy-Authorization: Basic " . base64_encode ("$proxy_user:$proxy_pass") . "\r\n\r\n");
while(!feof($proxy_fp)) {$proxy_cont .= fread($proxy_fp,4096);}
fclose($proxy_fp);
$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
echo "ERROR: " . $error_no . $error_string . "<br>";
return $proxy_cont;
}
$a = proxy_url("destination_ip:8080/httppost_test/recieve.php");
var_dump($a);
?>
But when i try the URL directly in the browser's address bar, it works fine. Any suggestions?
Thanks
Marinus