2009-11-27 44 views
0

我似乎無法通過POST通過PHP通過SSL提交表單。這裏快速瀏覽一下我的代碼,誰能告訴我什麼是錯的?無法通過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)我在窗體中鍵入東西,h它的提交按鈕

3)print_r($ _ POST)什麼也不打印!我預計它會被人口聚居!

如果我註釋掉與HTTPS相關的.htaccess文件中的三行並重復相同的實驗,那麼print_r($ _ POST)會爲我提供表單提交的結果。

我該如何讓我的表單發佈工作始終?

+0

你有沒有試過看,如果使用307而不是301使其行爲不同? – Amber 2009-11-27 00:12:50

回答

1

哦,我想通了這個問題

我的網頁瀏覽器的地址說https://www.helloworld.org/test/login/與HTTPS,但我的[形式行動=「http://www.helloworld.org/test/login」]沒有HTTPS。當我點擊提交時,.htaccess重定向回https,這可能會破壞POST信息。

因此,我所做的只是使用PHP打印相同的http或https協議,將瀏覽器url顯示到表單標記的操作中。