php headers - 发布并关注

发布于 2024-08-06 20:53:19 字数 47 浏览 2 评论 0原文

有人可以帮助我了解如何发布变量并按照帖子到达该页面吗?

问候菲尔

Could someone help me on how to post variables and follow the post to that page?

Regards Phil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

提笔书几行 2024-08-13 20:53:19

您可以使用 CURL 来做到这一点:

$ch = curl_init();
$data = array('name' => 'Foo', 'bar' => 'goo');

curl_setopt($ch, CURLOPT_URL, 'http://myserver.com/post.php');

//post the data
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

//enable RETURN_TRANSFER so curl_exec() returns result of the request
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

You can use CURL to do that:

$ch = curl_init();
$data = array('name' => 'Foo', 'bar' => 'goo');

curl_setopt($ch, CURLOPT_URL, 'http://myserver.com/post.php');

//post the data
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

//enable RETURN_TRANSFER so curl_exec() returns result of the request
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
curl_close($ch);

echo $result;
却一份温柔 2024-08-13 20:53:19

您无法通过重定向执行 HTTP POST 请求。您可以使用如下参数进行 GET 重定向:

header('Location: target_page.php?a=foo&b=bar');

You can't do an HTTP POST request via a redirect. You can do a GET redirect with parameters like this though:

header('Location: target_page.php?a=foo&b=bar');
对你的占有欲 2024-08-13 20:53:19

如果要将数据从一个页面传递到另一页面,然后重定向到该页面,可以将数据临时存储在 $_SESSION 超全局数组中,然后重定向到新页面。一旦到达那里,您就可以从数组中获取数据,并在需要时取消设置()它。

if you want to pass data from one page to another and then redirect to that page, you can temporarily stash the data in the $_SESSION superglobal array and then redirect to the new page. once you're there you can then get the data back out of the array and unset() it if need be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文