...

View Full Version : SOLVED: authenticate proxy server with file_get_contents()



Coastal Web
01-04-2012, 01:56 AM
Hey there guys,
I'm trying to figure out how to use file_get_contents with a user/pass authenticated proxy server....

I've tried the following two implentations from snippets l've found online in various places, but neither seem to work.

Can anyone see what l'm doing wrong?



$auth = base64_encode('xxx:xxx');
$url = 'http://ipchicken.com';

$opts = array(
'http' => array (
'method'=>'GET',
'header'=>"Authorization: Basic $auth",
'proxy'=> 'tcp://69.162.140.112:62266'
)
);
$ctx = stream_context_create($opts);

file_get_contents($url, false, $ctx);


$aContext = array(
'http' => array(
'proxy' => "tcp://69.162.140.112:62266",
'request_fulluri' => True,
'userid'=>"xxx",
'password'=>"xxx"

),
);

$context = stream_context_create($aContext);

echo file_get_contents("http://www.ipchicken.com", 0, $context);

PS> my user/pass is correct l've triple checked.

Coastal Web
01-05-2012, 02:31 AM
Got it with:


<?php


$auth = base64_encode('username:password');
$url = 'http://ipchicken.com';


$opts = array(
'http' => array (
'method'=>'GET',
'proxy'=>'tcp://69.162.120.112:62266',
'request_fulluri' => true,
'header'=> array("Proxy-Authorization: Basic $auth", "Authorization: Basic $auth")

),
'https' => array (
'method'=>'GET',
'proxy'=>'tcp://69.162.120.112:62266',
'request_fulluri' => true,
'header'=> array("Proxy-Authorization: Basic $auth", "Authorization: Basic $auth")
)
);
$ctx = stream_context_create($opts);
$content = file_get_contents($url,false,$ctx);

echo $content;

?>


Trick is to use both Proxy-Authorization and Authorization in the header.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum