在 PHP 中声明 POST 变量

发布于 2024-11-16 10:10:14 字数 567 浏览 0 评论 0原文

因此,我正在构建一个 Web 应用程序,它使用 iframe 提交异步提交到外部 .php 服务/从外部 .php 服务提取数据。我的项目面临新的限制,需要能够提取大量数据。通常,我只会将外部 .php 服务重定向回我的本地页面,并将数据作为查询字符串附加到 URL,但我认为这不安全,因为可能会有超过 5,000 个字符长的块数据(更不用说我可能会在一个请求中提取最多 3 个“块”)。

那么,我向大家提出的问题是,如何在 .php 服务中声明 POST 变量?此外,如果我声明一个 POST 变量,它实际上会到达我通过 Header('Location: someLocation.php'); 重定向到的页面吗? (我隐隐怀疑它不会)。

如果这不是解决此问题的最佳方法,并且有更好的方法从 .php 文件重定向到带有声明的 POST 变量的外部位置,请告诉我。

***过去,我使用 javascript 将表单附加到 iframe 页面,用我需要的内容填写文本字段,将表单指向外部页面,然后提交。这不是一个可行的替代方案,因为 .php 作为服务运行,因此我在其中放置的任何 JavaScript 都不会执行,因为浏览器永远不会呈现该页面。

此致,

So I am building a web application that uses iframe submission to asynchronously submit to / pull data from an external .php service. I have a new constraint on my project that requires being able to pull a large amount of data down. Normally I would just have the external .php service redirect back to my local page with the data appended to the URL as a query string, but I don't think this is safe as there is the potential to have 5,000+ character long chunks of data (not to mention that I may be pulling up to 3 "chunks" in a single request).

My question to you all, then, is how can I go about declaring a POST variable in my .php service? In addition, if I declare a POST variable will it actually make it to the page that I redirect to via Header('Location: someLocation.php'); (I have a sneaking suspicion that it will not).

If this is not the best way to approach this and there is a better way to, from a .php file, redirect to an external location with declared POST variables please let me know.

***In the past I have used javascript to append a form to an iframe page, fill out text fields with what I needed, point the form at an external page, and then submit it. This is not a viable alternative as the .php is running as a service and therefore any javascript that I place within it will not be executed as the page is never rendered by a browser.

Best regards,

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

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

发布评论

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

评论(2

岁月如刀 2024-11-23 10:10:14

利用会话变量。
这应该让您开始


由于以下评论而更新:

您可以尝试使用 cURL 发送帖子

Utilize session variables.
This should get you started


Update due to comments below:

You could try using cURL to send the posts

追星践月 2024-11-23 10:10:14

您不需要在 PHP 中“声明”post 变量。您只需通过 POST 提交数据并从 $_POST 检索数据即可。

如果您想使用双方法服务,以便它可以执行 GET 和 POST,您可以这样做:

switch ($_SERVER['REQUEST_METHOD']) {
    case 'POST':
        $myvar = $_POST['myvar'];
        break;
    case 'GET':
        $myvar = $_GET['myvar'];
        break;
    default:
        die("Unsupport request method");
}

或者,您可以使用 $_REQUEST['myvar'] 代替,它是 GET 和 POST 的组合同时,但最好使用您想要的特定超全局变量,而不是希望通过 _REQUEST 正确配置。

You don't "declare" a post variable within PHP. You simply submit your data via POST and retrieve it from $_POST.

If you want to dual-method your service so it can do GET and POST, you can do:

switch ($_SERVER['REQUEST_METHOD']) {
    case 'POST':
        $myvar = $_POST['myvar'];
        break;
    case 'GET':
        $myvar = $_GET['myvar'];
        break;
    default:
        die("Unsupport request method");
}

Alternatively, you can use $_REQUEST['myvar'] instead, which is a combination of GET and POST simultaneously, but it's best to use the specific superglobal you want instead of hoping things are configured correctly with _REQUEST.

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