Skip to content
Advertisement

Php Curl adding Params

Im a newbie im trying to get a script to trigger another script with Curl in PHP but it dosent seem to be sending the paramaters.

Is there a seperate function to append 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);
?>

Could anyone point me in the right direction??

Advertisement

Answer

You need curl_setopt() along with the CURLOPT_POSTFIELDS param. That’ll POST the given params to the target page.

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

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement