日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP防SQL注入攻击

發布時間:2024/1/17 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP防SQL注入攻击 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一般性的防注入,只要使用php的 addslashes 函數就可以了。 PHP代碼
  • $_POST?=?sql_injection($_POST);??
  • $_GET?=?sql_injection($_GET);??
  • ??
  • function?sql_injection($content)??
  • {??
  • if?(!get_magic_quotes_gpc())?{??
  • if?(is_array($content))?{??
  • foreach?($content?as?$key=>$value)?{??
  • $content[$key]?=?addslashes($value);??
  • }??
  • }?else?{??
  • addslashes($content);??
  • }??
  • }??
  • return?$content;??
  • }?
  • 做系統的話,可以用下面的代碼 PHP代碼
  • ?????
  • function?inject_check($sql_str)?{??????
  • ??return?eregi('select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile',?$sql_str);????//?進行過濾??????
  • }??????
  • ?????
  • ?????
  • function?verify_id($id=null)?{??????
  • ??if?(!$id)?{?exit('沒有提交參數!');?}????//?是否為空判斷??????
  • ??elseif?(inject_check($id))?{?exit('提交的參數非法!');?}????//?注射判斷??????
  • ??elseif?(!is_numeric($id))?{?exit('提交的參數非法!');?}????//?數字判斷??????
  • ??$id?=?intval($id);????//?整型化??????
  • ?????
  • ??return??$id;??????
  • }??????
  • ?????
  • ?????
  • function?str_check(?$str?)?{??????
  • ??if?(!get_magic_quotes_gpc())?{????//?判斷magic_quotes_gpc是否打開??????
  • ????$str?=?addslashes($str);????//?進行過濾??????
  • ??}??????
  • ??$str?=?str_replace("_",?"\_",?$str);????//?把?'_'過濾掉??????
  • ??$str?=?str_replace("%",?"\%",?$str);????//?把?'%'過濾掉??????
  • ?????
  • ??return?$str;???????
  • }??????
  • ?????
  • ?????
  • function?post_check($post)?{??????
  • ??if?(!get_magic_quotes_gpc())?{????//?判斷magic_quotes_gpc是否為打開??????
  • ????$post?=?addslashes($post);????//?進行magic_quotes_gpc沒有打開的情況對提交數據的過濾??????
  • ??}??????
  • ??$post?=?str_replace("_",?"\_",?$post);????//?把?'_'過濾掉??????
  • ??$post?=?str_replace("%",?"\%",?$post);????//?把?'%'過濾掉??????
  • ??$post?=?nl2br($post);????//?回車轉換??????
  • ??$post?=?htmlspecialchars($post);????//?html標記轉換??????
  • ?????
  • ??return?$post;??????
  • }??
  • 總結

    以上是生活随笔為你收集整理的PHP防SQL注入攻击的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。