form with post method stops working when php extension is off

前端 未结 3 1058
别跟我提以往
别跟我提以往 2020-12-12 07:46

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

相关标签:
3条回答
  • 2020-12-12 08:03

    you can use this method also

    htmlspecialchars(basename($_SERVER["PHP_SELF"], '.php'), ENT_QUOTES, "utf-8")
    
    0 讨论(0)
  • 2020-12-12 08:12

    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.

    0 讨论(0)
  • 2020-12-12 08:23

    Due to HTTP/1.1 regulations POST data cannot be carried through redirects. While there is a redirect code (307) which should allow POST data to be carried through a redirect, not all servers will support it due to potential security vulnerabilities.

    Also note that both 302 and 307 are declared as "temporary" redirects, meaning that at some point in the future, it will not be, as such a cache control header should be sent indicating when it should check if it has been changed. The type of redirect you're doing here seems more like a permanent change, in which case a 301 should be sent. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

    All of redirect issues aside, it's usually bad form (pun intended) for a form submission to hit any sort of redirects, as it appears 'phishy'. You should either submit directly to the page in question with: <?=$_SERVER['REQUEST_URI']; ?> or simply not provide an action attribute. As of HTML 5.0 the action attribute is not required http://www.w3schools.com/tags/att_form_action.asp. If you want to follow HTML 4.0 standards action="" also works in the same manner, and is correct to the specifications (as the action is a relative url, a blank path means "here").

    0 讨论(0)
提交回复
热议问题