要远程提交 PHP,你可以使用以下方法之一:
<?php
// 设置 POST 请求的 URL
$url = 'http://example.com/submit.php';
// 设置 POST 请求的参数
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
// 创建一个 cURL 句柄
$ch = curl_init();
// 设置 cURL 选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 执行 POST 请求并获取响应
$response = curl_exec($ch);
// 关闭 cURL 句柄
curl_close($ch);
// 处理响应
echo $response;
?>
<?php
// 设置 POST 请求的 URL
$url = 'http://example.com/submit.php';
// 设置 POST 请求的参数
$data = array(
'param1' => 'value1',
'param2' => 'value2'
);
// 创建一个请求头
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
)
);
// 发送 POST 请求并获取响应
$response = file_get_contents($url, false, stream_context_create($options));
// 处理响应
echo $response;
?>
无论你选择哪种方法,都需要确保远程服务器允许接收和处理 PHP 提交,并且你具有适当的权限来访问远程服务器。
上一篇:php的execute
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站