I need to get webpage's content ,I cant use Curl as it is not enabled.I tried the below code But it is not working.
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$fp = fopen($_GET['url'], 'r', false, $context);
if($fp)
fpassthru($fp);
fclose($fp);
exit;
The code produce an error
Warning: fopen(http://www.google.com/search?&q=site:www.myspace.com+-intitle:MySpaceTV+%22Todd Terje%22) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
you can use old-fashioned code, like:
$CRLF = "\r\n";
$hostname = "www.something.com";
$headers[] = "GET ".$_GET['url']." HTTP/1.1";
$headers[] = "Host: ".$hostname;
$headers[] = "Accept-language: en";
$headers[] = "Cookie: foo=bar";
$headers[] = "";
$remote = fsockopen($hostname, 80, $errno, $errstr, 5);
// a pinch of error handling here
fwrite($remote, implode($CRLF, $headers).$CRLF);
$response = '';
while ( ! feof($remote))
{
// Get 1K from buffer
$response .= fread($remote, 1024);
}
fclose($remote);
Update: Good thing about this solution is that it doesn't rely on fopen wrappers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With