<form action="MyForm.action" method="post">
託管在不同的服務器上。
我想我的PHP腳本張貼這種形式並顯示結果
我怎樣才能做到這一點?
<form action="MyForm.action" method="post">
託管在不同的服務器上。
我想我的PHP腳本張貼這種形式並顯示結果
我怎樣才能做到這一點?
要從PHP腳本發佈表單,您需要使用cURL。下面是一個示例
<?php
$url = 'http://domain.com/get-post.php';
$fields = array(
'lname'=>urlencode($last_name),
'fname'=>urlencode($first_name),
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
// Initialize curl
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
// Results of post in $result
?>
'CURLOPT_POST'應該是一個布爾'curl_setopt($ ch,CURLOPT_POST,count($ fields)> 0);'。 'CURLOPT_POSTFIELDS'可以是一個數組(你不需要「url-ify」它)'curl_setopt($ ch,CURLOPT_POSTFIELDS,$ fields);'http://php.net/manual/en/function.curl- setopt.php – 2012-02-14 22:09:15
讓cURL進行URL編碼! – 2012-02-15 09:07:54
發佈表單是什麼意思? – 2012-02-14 18:18:27