无法使用 PHP over SSL 通过 POST 提交表单
我似乎无法使用 PHP over SSL 通过 POST 提交表单。这是我的代码的快速浏览,有人能告诉我出了什么问题吗?
我的 .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) 会给出表单提交的结果。
如何使我的表单始终有效?
I can't seem to submit a form via POST with PHP over SSL. Here's a quick look at my code, can anyone tell me what's wrong?
My .htaccess file
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]
Here's 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); ?>
I take the following actions:
1) Go to http://www.helloworld.org/test/login/ (my browser will then automatically show the https version)
2) I type something into the form and hit the submit button
3) The print_r($_POST) prints nothing! I expected it to be populated!
If I comment out the three lines in the .htaccess file related to the HTTPS and repeat the same experiment, then the print_r($_POST) gives me the results of the form submission.
How do i make my form post work all the time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,我找到了问题
我的网络浏览器地址显示 https://www.helloworld.org/test /login/ 带有 https,但我的 [form action="http://www.helloworld.org/test/login"] 没有 https。当我点击提交时,.htaccess 重定向回 https,这可能会破坏 POST 信息。
所以我所做的就是使用 PHP 打印相同的 http 或 https 协议,将浏览器 url 显示到表单标记的操作中。
Oh, i figured out the problem
My web browser address says https://www.helloworld.org/test/login/ with the https but my [form action="http://www.helloworld.org/test/login"] does not have the https. When I hit submit, the .htaccess redirects back to https, which probably destroys the POST information.
So all I did was use PHP to print the same http or https protocol displayed the browser url into the action of the form tag.