views:

55

answers:

3

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

+2  A: 

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

adam
+1  A: 

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.

Tim Green
A: 
elias