Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

form with post method stops working when php extension is off

On my site I use htaccess url rewriting to remove php extensions completly from php files.

Php extension gets removed completly, /file.php maps to /file.

My problem is that php forms with POST method stop working when remove php rule is active.

I am using :

 action="<?php echo $_SERVER["PHP_SELF"]?>"

in action attribute of forms.

I am sure that this is not a htaccess or browser cache related issue because My htaccess regex is matching against both methods GET|POST. and I am using 302 to redirect.

My form url is /signup.php, It chages to /signup when I type /signup.php, Do I need to replace PHP_SELF with /signup in action attribute?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use $_SERVER["REQUEST_URI"] rather than $_SERVER["PHP_SELF"].

Per the PHP documentation (emphasis mine):

$_SERVER['PHP_SELF'] is

The filename of the currently executing script, relative to the document root.

whereas $_SERVER['REQUEST_URI'] is

The URI which was given in order to access this page; for instance, '/index.html'.

Since you are rewriting your URLs to remove the .php extension, you should no longer refer to the script's filename, which contains the extension, but rather to the URI of the current page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...