tags:

views:

252

answers:

1

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?

A: 

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.

John