scz*_*vos 5 javascript php parsing form-submit
我想用PHP(可能需要JS)创建一个脚本来将POST数据发送到另一个网页并返回结果.
例如,域A将具有带有文本框和提交按钮的表单,域B将具有将填充文本框并按下提交按钮并返回生成的HTML页面的脚本.
以下代码行可以写在另一个PHP脚本上,
//set POST variables
$url = 'the website from which you need data through post';
$fields = array(
//post parameters to be sent to the other website
'text'=>urlencode($_POST['text']), //the post request you send to this script from your domain.
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$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);
//close connection
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
现在$ result将包含从其他网站收到的文本.