-
File_Get_Contents
OK, simple enough command
$string = file_get_contents ( "http://www.google.com" );
And it used to work superbly! however now my computer must use a proxy server to access the internet and this doesnt work anymore!
Please does anyone know how I can tell this command to use http://myproxyserver:8080 note I also have to type in a username password and domain name when I am connecting through this, so is there a way I can put this in as well.
Thanks In Advanced
-
Have u tryed using fopen?
http://uk.php.net/manual/en/function.fopen.php
There is also a comment on how to use a proxy server there.
-
Cheers
I wont be able to test until I am back in work... but just a little question, from the code below how will I get the source code of "www.google.com" into $string? (I am a newbie)
Code:
Based on a previous code, here is the getThroughProxy function, with proxy Basic authentification :
function getthroughproxy
($myfiles,
$proxyhost="0.0.0.0",
$proxyport=0,
$proxyuser = '',
$proxypass = ''
)
{
$errno = '';
$errstr = '';
$datei = fsockopen($proxyhost, $proxyport, &$errno, &$errstr,30);
if( !$datei )
{
return array('headers'=>false,
'content'=>false,
'errno'=>$errno,
'errstr'=>$errstr);
// ^^^ proxy not available
} else
{
fputs($datei,"GET $myfiles HTTP/1.0\n");
if ('' !== $proxyuser)
{
fputs($datei, 'Proxy-Authorization: Basic '.base64_encode("$proxyuser:$proxypass")."\n");
}
fputs($datei, "\n\n");
$zeile = '';
while (!feof($datei))
{
$zeile =$zeile.fread($datei,4096);
}
}
fclose($datei);
return array('headers'=>substr($zeile,0,strpos($zeile,"\r\n\r\n")),
'content'=>substr($zeile,strpos($zeile,"\r\n\r\n")+4),
'errno'=>$errno,
'errstr'=>$errstr);
}