重定向发布请求以使用PHP

dre*_*nda 0 php post get http

我需要一个PHP脚本来获取POST请求,并将其重定向到另一个页面,作为GET请求,其中包含URL中的所有参数.

这可能吗?

Jen*_*ers 5

您可以使用该函数http_build_query()从中生成GET查询字符串$_POST.

然后将其附加到重定向URL并header()与位置一起使用以进行重定向,例如:

$newURL = 'http://example.com/script.php?' . http_build_query($_POST);
header("Location: {$newURL}");
Run Code Online (Sandbox Code Playgroud)