跨域表单提交不一致

时间:2017-01-28 21:08:04

标签: php html cross-domain form-submit

我有两个域名A和B.

托管表单A/inquire,向B/form-submission提交帖子请求 B接受B/form-submission的POST请求,并重定向到A/thankyou

这里有一个棘手的问题是A在<iframe>内托管表单,因此当用户提交表单时,iframe会跳转到B然后返回到A.

大约10-20%的用户遇到问题,提交表单会导致iframe无法重定向到A/thankyou,但表单数据总是会被保存,因此B/form-submission的脚本必须要完成。

B / form-submission(PHP):

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Accept-Encoding");
header('Access-Control-Allow-Methods: GET, POST, PUT');

... process form and insert data into db - works 100% of the time ...

header("Location: A/thankyou");
exit();

当然,我自己无法重现这一点......

有没有办法提高这种可靠性?它似乎与我的表单处理无关,因为在重定向之前发生的最后一件事是总是经历的数据库插入。

1 个答案:

答案 0 :(得分:0)

感谢评论者Gabriel和Taron。

Ruby on rails 4 app does not work in iframe

在远程站点上破坏iFrame的设置是X-Frame-Options。默认情况下,此设置为SAMEORIGIN,可防止内容加载跨域:

config.action_dispatch.default_headers = {
    'X-Frame-Options' => 'SAMEORIGIN'
}

添加此修复我的问题