2013-05-26 54 views
0

以下僅驗證一個文本框(txt1)。如果我有一系列位於表格(這是動態填充的)旁邊的文本框,我如何將文本框的整個值分配給一個會話?在PHP中爲會話分配表格

有沒有可能?

或者你能建議我一個出路嗎?

 <?php 
     if(isset($_POST['sendtwo'])) 
      { if($_POST['txt1'] == '') 
      {echo 'txt1 is empty!'; return;} else {$_SESSION['loged'] = $_POST['txt1'];} 
      } 
     if(isset($_POST['sendt']) || isset($_POST['sendtwo'])) 
     {if(isset($_SESSION['loged'])) echo $_SESSION['loged']; echo "<table border='1'><tr><td>form 2 is here!</rd></tr>"; 
     ?> 
+0

不要忘記保護XSS –

+0

怎麼樣?你能告訴我你看到了什麼樣的漏洞嗎?謝謝 –

+0

man,會話變量對於服務器來說非常重,不要做或者儘量減少對它的使用 – DmitryK

回答

0
//try this 
    <?php 
    if(isset($_POST['sendtwo'])) 
     { if($_POST['txt1'] == '') 
     {echo 'txt1 is empty!';} else {$_SESSION['loged'] = $_POST['txt1'];} 
     } 
    if(isset($_POST['sendt']) || isset($_POST['sendtwo'])) 
    { 
    if(isset($_SESSION['loged'])) { 
    echo $_SESSION['loged']; 
    echo " border='1'>form 2 is here!"; 
    } 
} 
    ?> 
0

像這樣的事情?我不確定你的意思:

<?php 
    if(isset($_POST['sendtwo'])) 
     { 
     if($_POST['txt1'] == '') 
     {echo 'txt1 is empty!'; return;} 
     else{ 
      foreach($_POST as $Key => $Posted) 
      $_SESSION[$Key] = $Posted; 
      } 
     } 
    if(isset($_POST['sendt']) || isset($_POST['sendtwo'])) 
    {if(isset($_SESSION['loged'])) echo $_SESSION['loged']; echo "<table border='1'><tr><td>form 2 is here!</rd></tr>"; 
    ?>