我想創建一個php腳本,它會將post變量傳遞給表單並返回信息。我已經成功完成了這個命令行使用以下命令:PHP cURL沒有正確發佈數據
curl --data "cid=800.10" http://online.starmont.ca/java/www?html=main
不幸的是,我似乎無法得到這與PHP的工作。如果有人有任何建議,將不勝感激。提前致謝。這是我現在使用的PHP腳本。
<?php
//set up a connection variable for the page you will post data to
$curl_connection = curl_init('http://online.starmont.ca/java/www?html=main');
//curl basic setup
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//$_POST variables to pass
$post_item = 'cid='.strip_tags($_POST['800.10']);
//format the $post_items into a string
$post_string = implode ('&', $post_items);
//send the $_POST data to the new page
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
print ($result);
curl_close($curl_connection);
?>