我想创建一个POST方法表单,将详细信息发送到另一台服务器上的PHP脚本(即,不是其localhost).这甚至可能吗?我想GET很好,POST也可以吗?
Mar*_*c B 20
<form method="POST" action="http://the.other.server.com/script.php">
Run Code Online (Sandbox Code Playgroud)
MMM*_*MMM 12
如果您想在服务器上执行此操作(即您希望服务器充当代理),可以使用cURL.
//extract data from the post
extract($_POST);
//set POST variables
$url = 'http://domain.com/get-post.php';
$fields_string = "";
$fields = array(
'lname'=>urlencode($last_name), // Assuming there was something like $_POST[last_name]
'fname'=>urlencode($first_name)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = 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)
但是,如果您只是想将POST请求发送到另一台服务器,则只需更改action属性即可:
<form action="http://some-other-server.com" method="POST">
Run Code Online (Sandbox Code Playgroud)