久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何實現(xiàn)sql防注入?

      php實現(xiàn)sql防注入方法:1、execute代入?yún)?shù)法,代碼為【$stmt->execute(array($_POST[$j], $_POST[$i])】;2、bindParam綁定參數(shù),代碼為【$stmt->bindPara("")】。

      php如何實現(xiàn)sql防注入?

      php實現(xiàn)sql防注入方法:

      方法一:execute代入?yún)?shù)

      <?php if(count($_POST)!= 0) {   $host = 'aaa';   $database = 'bbb';   $username = 'ccc';   $password = '***';   $num = 0;   $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);//創(chuàng)建一個pdo對象   foreach ($_POST as $var_Key => $var_Value) {     //獲取POST數(shù)組最大值     $num = $num + 1;   }   //下標(biāo)為i的數(shù)組存儲的是商品id, 下標(biāo)為j數(shù)組的存儲的是此商品的庫存   for($i=0;$i<$num;$i=$i+2)   {     //庫存下標(biāo)     $j = $i+1;     //判斷傳遞過來的數(shù)據(jù)合法性     if(is_numeric(trim($_POST[$i])) && is_numeric(trim($_POST[$j]))){       //禁用prepared statements的仿真效果       $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);       //查詢數(shù)據(jù)庫中是否存在該ID的商品       //當(dāng)調(diào)用 prepare() 時,查詢語句已經(jīng)發(fā)送給了數(shù)據(jù)庫服務(wù)器,此時只有占位符 ? 發(fā)送過去,沒有用戶提交的數(shù)據(jù)       $stmt = $pdo->prepare("select good_id from delphi_test_content WHERE good_id = ?");       //當(dāng)調(diào)用到 execute()時,用戶提交過來的值才會傳送給數(shù)據(jù)庫,他們是分開傳送的,兩者獨立的,SQL攻擊者沒有一點機會。       $stmt->execute(array($_POST[$i]));       //返回查詢結(jié)果       $count = $stmt->rowCount();       //如果本地數(shù)據(jù)庫存在該商品ID和庫存記錄,就更新該商品的庫存       if($count != 0)       {         $stmt = $pdo->prepare("update delphi_test_content set content = ? WHERE good_id = ?");         $stmt->execute(array($_POST[$j], $_POST[$i]));       }       //如果本地數(shù)據(jù)庫沒有該商品ID和庫存記錄,就新增該條記錄       if($count == 0)       {         $stmt = $pdo->prepare("insert into delphi_test_content (good_id,content) values (?,?)");         $stmt->execute(array($_POST[$i], $_POST[$j]));       }     }   }   $pdo = null;   //關(guān)閉連接 } ?>

      方法二:bindParam綁定參數(shù)

      <?php if(count($_POST)!= 0) {   $host = 'aaa';   $database = 'bbb';   $username = 'ccc';   $password = '***';   $num = 0;   $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);//創(chuàng)建一個pdo對象   foreach ($_POST as $var_Key => $var_Value) {     //獲取POST數(shù)組最大值     $num = $num + 1;   }   //下標(biāo)為i的數(shù)組存儲的是商品id, 下標(biāo)為j數(shù)組的存儲的是此商品的庫存   for($i=0;$i<$num;$i=$i+2)   {     //庫存下標(biāo)     $j = $i+1;     //判斷傳遞過來的數(shù)據(jù)合法性(此數(shù)據(jù)為商品編號以及庫存,嚴格來說字符串全是由數(shù)字組成的)     if(is_numeric(trim($_POST[$i])) && is_numeric(trim($_POST[$j]))){       //查詢數(shù)據(jù)庫中是否存在該ID的商品       $stmt = $pdo->prepare("select good_id from delphi_test_content WHERE good_id = ?");       $stmt->execute(array($_POST[$i]));       $stmt->bindParam(1,$_POST[$i]);       $stmt->execute();       //返回查詢結(jié)果       $count = $stmt->rowCount();       //如果本地數(shù)據(jù)庫存在該商品ID和庫存記錄,就更新該商品的庫存       if($count != 0)       {         $stmt = $pdo->prepare("update delphi_test_content set content = ? WHERE good_id = ?");         $stmt->execute(array($_POST[$j], $_POST[$i]));         $stmt->bindParam(1,$_POST[$j]);         $stmt->bindParam(2,$_POST[$i]);         $stmt->execute();       }       //如果本地數(shù)據(jù)庫沒有該商品ID和庫存記錄,就新增該條記錄       if($count == 0)       {         $stmt = $pdo->prepare("insert into delphi_test_content (good_id,content) values (?,?)");         $stmt->bindParam(1,$_POST[$i]);         $stmt->bindParam(2,$_POST[$j]);         $stmt->execute();       }     }   }   $pdo = null;   //關(guān)閉連接 } ?>

      相關(guān)學(xué)習(xí)推薦:PHP編程從入門到精通

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號