要发送POST请求并带参数跳转页面,可以使用PHP的header
函数来实现。以下是一个示例代码:
<?php
// 要跳转的URL
$url = 'http://example.com/destination.php';
// 要发送的POST参数
$data = array(
'param1' => 'value1',
'param2' => 'value2',
);
// 构建POST请求的参数字符串
$postData = http_build_query($data);
// 设置header头信息
$header = array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($postData)
);
// 发送POST请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
curl_close($ch);
// 跳转到目标页面
header('Location: ' . $url);
exit;
?>
在上面的示例代码中,首先定义了要跳转的URL和要发送的POST参数。然后,使用http_build_query
函数将参数数组转换为POST请求的参数字符串。接下来,设置header
头信息,包括Content-Type
和Content-Length
。然后,使用curl
库发送POST请求,并将返回的响应保存在$response
变量中。最后,使用header
函数将页面跳转到目标URL。
下一篇:伪静态如何隐藏php后缀
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站