Jump to content

Working behind a prox


putty

Recommended Posts

Am working behind a prox, this is causing problems when I try to save an image from another server.

 

Dose anyone know how to authenticate (user name and password) and run this code?

 

<?php
$url = "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&layers=global_mosaic&styles=&srs=EPSG:4326&bbox=110,-45.5,160,-8&WIDTH=1280&HEIGHT=960&format=image/jpeg ";
$file = file_get_contents($url);
$path = "./map/test.jpg";
if(file_put_contents($path,$file)){
//run map script
}
else{
//log error
}
?>

Link to comment
https://forums.phpfreaks.com/topic/76935-working-behind-a-prox/
Share on other sites

I have tried

 

<?php
$opts = array('http' => array('proxy' => 'envproxy.env.qld.gov.au:8080'));
$context = stream_context_create($opts);


$url = "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&layers=global_mosaic&styles=&srs=EPSG:4326&bbox=110,-45.5,160,-8&WIDTH=1280&HEIGHT=960&format=image/jpeg ";
$file = file_get_contents($url, false, $context);
$path = "./map/test.jpg";
if(file_put_contents($path,$file)){
echo "Yahoooooo";
}
else{
echo "NOOOOOO"
}

?>

This connects throw a proxy but doesn’t handle any user name and password authentication.

 

I have never tried to do anything line this before can someone please help me out.

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/76935-working-behind-a-prox/#findComment-390322
Share on other sites

Ok I came across cURL, but before I spend time working out how to compile it can anyone tell me if it will solve my problem?

 

And if someone can give me an example of how to use cURL to authenticate a proxy, that would be great.

 

I think it is something like this…

 

<?php
$url = "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&layers=global_mosaic&styles=&srs=EPSG:4326&bbox=110,-45.5,160,-8&WIDTH=1280&HEIGHT=960&format=image/jpeg ";

$cUrl = curl_init();
curl_setopt($cUrl, CURLOPT_URL, $url);
curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cUrl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($this->cUrl, CURLOPT_PROXY, '147.***.***.***:8080');
curl_setopt($this->cUrl, CURLOPT_PROXYUSERPWD, 'test_user:test_password');
$PageContent = curl_exec($cUrl);

$file = file_get_contents($url);
$path = "./map/test.jpg";
if(file_put_contents($path,$file)){
//desplay image
}
else{
// error handeling
}

curl_close($cUrl);
?>

Link to comment
https://forums.phpfreaks.com/topic/76935-working-behind-a-prox/#findComment-391042
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.