2011-11-24 268 views
0

php首先執行form action =」 它不會等待'form action ='from html ... 怎麼了?

<?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] 
+7

它做什麼..? –

+0

你的問題沒有意義,你的代碼看起來很好,所以請reedit你的問題謝謝... –

+1

它不等待內容提交,當我打開頁面,我已經看到回聲 – user1047737

回答

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=""提交頁面中執行過。

+0

如何在成功提交後排除php代碼? – user1047737

+0

我不明白,爲什麼你需要排除php代碼? – Cesar

+0

我想在我提交內容後運行php代碼... – user1047737

0

正確的方法來檢查POST是做

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

檢查特定字段名是不可靠的 - 你可以改變字段名稱,忘記更新,如果(),該領域可能會否則排除,等等...上面的代碼是100%可靠的,因爲它不依賴於表單本身的任何東西,除了提交方法。

+0

如果我把這段代碼包含到其他php文件中,它仍然不起作用,它只是在點擊提交後重定向到主頁面。 – user1047737

+0

你的代碼是否有任何重定向?使用HTTPFox或Firebugs Net等標籤查看瀏覽器和服務器之間的實際請求/響應。該表單可能會正常工作,並且您的代碼中的其他位置會導致重定向。 –

+0

是的我有這個代碼在PHP中if($ num == 0){redirect($ url-> url_base);出口; }否則 但如果我刪除它,它是stil重定向,但到PHP文件 – user1047737

相關問題