Forum Moderators: coopster
[us.php.net...]
I followed a tutorial and built my first script.
Unfortunately the tutorial only showed how to post one variable, and I need to post four.
The current script below seems only to post the last variable, how can I tweak this script so it posts all four.
<?php
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://www.site.com/form/");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"var1=these");
curl_setopt($ch,CURLOPT_POSTFIELDS,"var2=are");
curl_setopt($ch,CURLOPT_POSTFIELDS,"var3=my");
curl_setopt($ch,CURLOPT_POSTFIELDS,"var4=variables");
$result=curl_exec($ch);
curl_close($ch);
print $result;
?>
$post = array('var1' => 'these', 'var2' => 'are', 'var3' => 'my', 'var4' => 'variables');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
Try that
My script now looks like this:
<?php
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://www.site.com/form/");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,array("var1"=>"these","var2"=>"are","var3"=>"my","var4"=>"variables"));
$data=curl_exec($ch);
curl_close($ch);
?>
What I was trying to do with the $data variables was to contain the html code of the resulting page, so I can widdel it down to grab the content I needed. All I seem to be getting is a number, while at the same time, the html of the page is showing up on the page I'm running the script on.
How can I have the resulting page's html be confined to a variable, and not outputted into the php page?
Also, do I need to do anything special if var1 ends up being the size of a long text document? Are there size limits for text being sent via POST.
Thanks