【问题标题】:can't submit a form via POST with PHP over SSL无法通过 POST 使用 PHP over SSL 提交表单
【发布时间】:2009-11-27 00:01:57
【问题描述】:

我似乎无法通过 POST 使用 PHP over SSL 提交表单。快速浏览一下我的代码,谁能告诉我有什么问题?

我的 .htaccess 文件

RewriteEngine On
RewriteBase /test

RewriteCond %{HTTP_HOST} !^www\.helloworld\.org$ [NC]
RewriteRule ^(.*)$ http://www.helloworld.org/test/$1 [L,R=301]

# If i comment out these 3 lines, everything works fine
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (myaccount|register|registration|login)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

这里是 index.php

<?php $myurl = "http://www.helloworld.org".$_SERVER['REQUEST_URI']; ?>
<form method="post" action="<?=$myurl ?>">
<input name="text" />
<input type="submit" />
<?php print_r($_POST); ?>

我采取以下行动:

1) 转到http://www.helloworld.org/test/login/(我的浏览器会自动显示https版本)

2) 我在表单中输入一些内容并点击提交按钮

3) print_r($_POST) 什么也不打印!我预计它会被填充!

如果我注释掉 .htaccess 文件中与 HTTPS 相关的三行并重复相同的实验,那么 print_r($_POST) 会给我表单提交的结果。

如何让我的表单发布始终有效?

【问题讨论】:

  • 您是否尝试过使用 307 而不是 301 是否会导致其行为不同?

标签: ssl https


【解决方案1】:

哦,我发现问题了

我的网络浏览器地址显示 https://www.helloworld.org/test/login/ 带有 https,但我的 [form action="http://www.helloworld.org/test/login"] 没有 https。当我点击提交时,.htaccess 会重定向回 https,这可能会破坏 POST 信息。

所以我所做的只是使用 PHP 打印相同的 http 或 https 协议,将浏览器 url 显示到表单标签的操作中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2018-09-17
    • 2022-01-24
    • 2015-02-14
    • 2012-07-17
    • 2011-10-14
    • 2021-03-29
    相关资源
    最近更新 更多