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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.