使用 PHP 通过 HTTP Post 而非简单链接进行重定向
我有一个杂志出版商的网站,该网站有一个标准超链接,指向另一个托管该杂志电子版的网站。电子杂志托管网站有其 owm、每个出版物、身份验证方案、每个用户每个杂志。为了避免杂志订阅者必须同时登录两个网站,双方同意采取某种握手方式。
当重定向到杂志托管站点时,我必须发布一个包含一些值的小型 HTML 表单。我的第一个障碍是杂志出版商网站是 CMS 驱动的,所以我不能真的只用输入包围一个按钮并将其伪装成 POST 重定向。
到目前为止,我最干净的解决方案是创建一个新的、非公开的、小型的 PHP,原始杂志网站将链接到该 PHP。该 PHP 将呈现一个小型 HTML 表单,该表单将立即将 instelf 发布到杂志托管站点,因此当杂志读者作为杂志托管站点到达时,他已经进行了身份验证
I have one website, of a magazine publisher, and this site has a standard hyperlink to another site that hosts the electronic version of the magazine. The emagazine hosting site has it's owm, per publication, authentication scheme, per user per mag. In order to avoid magazine subscribers having to sign on to both sites, the parties have agreed on a kind of handshaking.
When redirecting to the magazine host site, I must post a small HTML form with a few values. My first obstacle is that the magazine publisher site is CMS driven, so I can't really just surround one button with inputs and disguise it as a POST redirect.
My cleanest solution so far to create a new, non public, little PHP that the originals magazine site will link to. This PHP will render a small HTML form that will immediately post instelf to the magazine hosting site, so when the magazine reader arrives as the magazine hosting site he is already auththenticate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能需要在服务器端使用 cURL(或带有
$context
参数的file_get_contents
)或在客户端使用$.post.我认为您不会仅仅因为服务器标头告诉它就说服大多数浏览器提交
POST
请求 - 这对于安全性来说是非常糟糕的。 (例如:如果您正在观看价值 10,000 美元的电视页面,亚马逊可以简单地告诉您的浏览器单击“立即购买”按钮。)PHP 示例
JS 示例
This probably needs to be done on the server side using cURL (or
file_get_contents
with a$context
parameter) or on the client side using a$.post
. I don't think you're going to convince most browsers to submit aPOST
request just because a server header told it to - it'd be awful for security. (For example: Amazon could simply tell your browser to click the "Buy It Now" button if you were on the page of a $10,000 TV.)PHP example
JS Example
您可以通过页面上的标头重定向来执行此操作,但它与表单提交不同,因此发布到的页面需要能够接受 GET 样式的表单提交,但您应该能够执行此操作使用如下代码:
请记住,如果您向浏览器打印任何内容,则 php 标头重定向将失败,这需要是第一个到达浏览器的内容。
You can do this with a header redirect on the page but it won't be the same as a form submission, so the page its posting to will need to be able to accept GET style form submissions, but you should be able to do this with code like the following:
Keep in mind if you print anything to the browser, the php header redirect will fail, this needs to be the first thing to hit the browser.