Php Curl Adds Params

Im a newbie trying to get a script to invoke another script with Curl in PHP, but it seems to be sending parameters.

Is there a separate function for adding parameters?

<?php $time = time(); $message = "hello world"; $urlmessage = urlencode( $message ); $ch = curl_init("http://mysite.php?message=$urlmessage&time=$time"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); ?> 

Can someone point me in the right direction?

+4
source share
2 answers

You need curl_setopt () along with the CURLOPT_POSTFIELDS parameter. This will be the POST of the given parameters to the landing page.

curl_setopt($ch, CURLOPT_POSTFIELDS, 'foo=1&bar=2&baz=3');

PS: also check http_build_query () , which is convenient when sending many variables.

+10
source

you need to set CURLOPT_POST as true and CURLOPT_POSTFIELDS => parameters

  curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); 

suggestion, set ' CURLOPT_RETURNTRANSFER ' as true to return the transfer as a return string curl_exec($ch) instead of direct output

+5
source

All Articles