php首先执行form action =“<! - ?php echo $ _SERVER ['PHP_SELF'];? - >

时间:2011-11-24 13:23:41

标签: php html action forum

php首先执行form action =“ 它没有等待来自html的'form action ='... 怎么了?

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
    echo "<br>You can use the following form again to enter a new name.";
}
?>

来自我的.htaccess。也许它正在制动代码

## Turn on and setup apache rewrite ##
RewriteEngine On
Options +Followsymlinks
RewriteBase /

## Dissable directory indexing ##
Options -Indexes

## Remove trailing slash from end of uri ##
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]

# Redirect to non.php extension
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$  $1 [R=301,L]

## Rewrite Rules ##
RewriteRule ^([0-9-a-z-A-Z-_]+)/?$ goto.php?id=$1 [L]
RewriteRule ^account/(.*)$  $1.php [L]

2 个答案:

答案 0 :(得分:4)

http://php.net/manual/pt_BR/reserved.variables.server.php

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><form action="" method="post">是等于的,因为$_SERVER['PHP_SELF']会返回执行中的脚本名称,而action=""也会提交给执行中的页面。

答案 1 :(得分:0)

检查POST的正确方法是

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   ... a POST has occurred ...
}

检查特定字段名称是不可靠的 - 您可能会更改字段名称并忘记更新if(),否则字段可能被排除等等...上面的代码是100%可靠的,因为它没有依赖于表单中的任何内容,除了提交方法之外。

相关问题