GET command is giving two kinds of ouput,why?
iam using GET command to get the content of a page.When i write the same command on shell prompt it gives correct result but when 开发者_StackOverflow社区i use that in PHP file then sometimes its giving correct result but sometimes it gives only half of the content i.e. end-half portion only.
Iam using following command in shell script :-
GET http://www.abc.com/ -H "Referer:http://www.abcd.com/"
and following in PHP file :-
$data=exec('GET http://www.abc.com/ -H "Referer:http://www.abcd.com/"');
echo $data;
Now please tell why this command is not giving full content of the page when im using it in php file.
exec
only returns the last line from the command output. To return the full output, pass in a second argument by reference:
exec('GET http://www.abc.com/ -H "Referer:http://www.abcd.com/"', &$data);
$data
will be an array with one element per line of output
Might be easier:
$data = `GET http://www.abc.com/ -H "Referer:http://www.abcd.com/"`;
echo $data;
Assuming shell_exec function (that's what the backtick ` really is) isn't disabled.
An alternative with pure php:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Referer: http://www.abc.com/\r\n"
)
);
$context = stream_context_create($opts);
$file = file_get_contents('http://www.abc.com/', false, $context);
精彩评论