2013-03-04 17 views
0

我有一個小表格:如何在提交時傳遞多個變量?

//GET the unit and community id 
$UNIT = $_GET['unit']; 
$COMID = $_GET['comid']; 

...//i have echoed $UNIT and $COMID to ensure that they do have values 
... 

<form action="ModifyNoteScript.php" method="post" /> 
     <input name="Comment" type="hidden" value="<?php echo $Comment; ?>" /> 
     <input name="UNIT" type="hidden" value="<?php echo $UNIT; ?>" /> 
     <input name="COMID" type="hidden" value="<?php echo $COMID; ?>" /> 
     <textarea name="Comment" cols="55" rows="6" class="text1" id="Comment"><?php echo $Comment; ?> 
     </textarea> 
     <br /> 
     <input type="submit" name="sendnotify" class="formbutton" id="Submit" value="Replace previous note with current" /> 
     </form> 

這是它:

enter image description here

,你可以看到我設置的變量commenttextarea

它經過的下一頁ModifyNoteScript.php沒有問題。

然而,其他兩個變量UNITCOMID由於某種原因,獲得通過的[blanks]

這裏是ModifyNoteScript.php樣子:

<?php 
include '../Check.php'; 
include '../CustomConnect.php'; 

$UNIT= $_POST['unit']; 
$COMID= $_POST['comid']; 
$NOTE= $_POST['Comment']; 


    $comment_update = mssql_query("UPDATE pmp_property__unit 
    SET 
    comments = '$NOTE' 
    WHERE 
    communityidy='$COMID' and 
    unit='$UNIT'") 
      or die ("Changes to Record could not be Saved."); 




?> 

爲什麼經過作爲空白兩個變量?

+1

什麼是自閉窗體標籤? – Musa 2013-03-04 19:14:56

回答

1

首先您的腳本對XSS攻擊開放,因爲您沒有進行任何驗證(至少這是它的表現)。

$UNIT = $_GET['unit']; // should be $_POST['UNIT'] 
$COMID = $_GET['comid']; // should be $_POST['COMID'] 

您試圖在使用POST提交它們時使用兩個GET變量,並且它們都是大寫。 請記住,GET和POST變量區分大小寫。

此外,你有一個input[type=hidden]textareaname和他們都提交。你應該改變其中的一個以避免混淆。

+0

非常感謝,你能給我一個我如何做驗證的例子,以確保我不會受到攻擊嗎? – 2013-03-04 19:50:29

+0

@АртёмЦарионов,這一切都歸結於你期望的GET變量。如果你期待一個int,你應該做'$ var =(int)$ _GET ['key'];'你應該沒問題。如果你期待一個字符串,那麼你應該使用REGEX和'preg_match'來定義字符串應該包含的字符。 – Shoe 2013-03-04 19:52:15

+0

謝謝!我實際上期待着一個組合! – 2013-03-04 19:52:54

1

ModifyNoteScript.php,在$_POST變量必須是:

$UNIT= $_POST['UNIT']; // uppercase 
$COMID= $_POST['COMID']; // uppercase 
$NOTE= $_POST['Comment']; 
1

檢查您name標籤和$_POST指標之間的差異情況。

你總是可以嘗試一個var_dump($_POST)看看你得到什麼。