dousongqiang2585
2011-11-24 13:23
浏览 188
已采纳

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

php executes first with form action=" it doesn't wait 'form action=' from html... what's wrong?

<?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.";
}
?>

from my .htaccess. maybe it's braking the code

## 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]

图片转代码服务由CSDN问答提供 功能建议

php首先执行form action =“ it is wait wait'form action ='from html ... 是什么问题?

 &lt;?php 
if(isset($ _ POST ['submit']))
 {
 $ name = $ _POST ['name'  ]; 
 echo“用户已提交表格并输入此名称:&lt; b&gt;  $ name&lt; / b&gt;“; 
 echo”&lt; br&gt;您可以再次使用以下表单输入新名称。“; 
} 
?&gt; 
    
 
 

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

  ##打开并设置apache重写## 
RewriteEngine On 
Options + Followsymlinks 
RewriteBase  / 
 
 ##不可用目录索引## 
Options -Indexes 
 
 ##从uri末尾删除尾部斜杠## 
RewriteCond%{REQUEST_FILENAME} .php -f 
RewriteCond%{REQUEST_URI}!/ $  
RewriteRule(。*)$ 1 \ .php [L] 
RewriteCond%{REQUEST_FILENAME}!-d 
RewriteRule ^(。+)/ $ / $ 1 [R = 301,L] 
 
#重定向到non.php  extension 
RewriteCond%{THE_REQUEST} ^ GET \ /([^ /] + /)* [^。] + \ .php(\?[^ \] *)?\ HTTP / 
RewriteRule ^(([^ /]  + /)* [^。] +)\。php $ 1 [R = 301,L] 
 
 ##重写规则## 
RewriteRule ^([0-9-azAZ -_] +)/?$  goto.php?id = $ 1 [L] 
RewriteRule ^ account /(.*)$ $ 1.php [L] 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudu9148 2011-11-24 13:31
    已采纳

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

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> and <form action="" method="post"> are equals because $_SERVER['PHP_SELF'] return the script name in execution and action="" submit to the page in execution too.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douxie5930 2011-11-24 14:26

    The proper method to check for a POST is to do

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

    checking for a particular field name is unreliable - you might change the field name and forget to update the if(), the field might get otherwise excluded, etc... The above code is 100% reliable as it doesn't depend on anything in the form itself, EXCEPT for the submission method.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题