在 PHP 中声明 POST 变量
因此,我正在构建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
利用会话变量。
这应该让您开始
由于以下评论而更新:
您可以尝试使用
cURL
发送帖子Utilize session variables.
This should get you started
Update due to comments below:
You could try using
cURL
to send the posts您不需要在 PHP 中“声明”post 变量。您只需通过 POST 提交数据并从 $_POST 检索数据即可。
如果您想使用双方法服务,以便它可以执行 GET 和 POST,您可以这样做:
或者,您可以使用
$_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:
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.