php/mysql的清理是如何工作的?
所以,我已经完成了我正在处理的大量站点,但是我现在想清理来自用户的数据 该网站是一个拍卖风格的网站。存在一个表单,该表单要求用户提供有关他们希望拍卖的物品的数据。表单发布时,数据被输入php中的变量,然后提交到数据库,例如:php/mysql的清理是如何工作的?,php,mysql,Php,Mysql,所以,我已经完成了我正在处理的大量站点,但是我现在想清理来自用户的数据 该网站是一个拍卖风格的网站。存在一个表单,该表单要求用户提供有关他们希望拍卖的物品的数据。表单发布时,数据被输入php中的变量,然后提交到数据库,例如: if(isset($_POST['title'])) { $allowedExts = array("gif", "jpeg", "jpg", "png");//array of allowed extensions $te
if(isset($_POST['title'])) {
$allowedExts = array("gif", "jpeg", "jpg", "png");//array of allowed extensions
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
/*
* Set variables for the _POST data (except the file).
*/
$title = $_POST['title'];
$description = $_POST['description'];
$type = $_POST['description'];
$startPrice = $_POST['startPrice'];
$reservePrice = $_POST['reservePrice'];
$buyPrice = $_POST['buyPrice'];
然后,它验证与表单一起上载的文件是否为有效格式和大小的图像,将其复制到其永久位置,并为图像设置URL变量
然后它进入数据库,如下所示:
if (!$this->db->query("INSERT INTO tbl_auction_listing VALUES(NULL, '$userid', '$title', '$description', '$img_url', '16', NOW(), NOW() + INTERVAL 5 DAY, '$startPrice', '$reservePrice', '$buyPrice', '0', '1')")) {
echo '<h2> Item did not enter successfully, please try again </h2>';
//redirect(site_url() . 'user/fail/'); exit();
}
if(!$this->db->query(“插入tbl_拍卖”列表值(空,$userid','$title','$description','$img_url','16',NOW(),NOW()+间隔5天,$startPrice','$reservePrice','$buyPrice','0','1')){
echo“项目未成功输入,请重试”;
//重定向(site_url().“user/fail/”);退出();
}
用户不能使用任何自定义HTML,也不能转义php中的当前命令以便执行shell命令,这一点非常重要
无论如何,一旦稍后从数据库中检索到项数据,它的格式与此类似(省略了一些行,只是想让您看看它是如何编码的)
$query=$this->db->query(“从项目{$item}中选择*,其中winning='1';”;
foreach($query->result()作为$row)
{
$currentHighBid=$row->bid;
//如果行为空,则表示没有出价-初始化变量并将合格出价设置为100 satoshi。
如果($currentHighBid==NULl){
$currentHighBid=NULL;
$currentWinner=NULL;
$WinnerMaxId=NULL;
$ip=NULL;
$WINING=NULL;
$qualifyingbid=$startprice;
$displayQualifyingBid=number_格式($qualifyingbid,8,'.','');//格式为小数点而非科学符号
}
否则{
$currentHighBid=$row->bid;
$currentWinner=$row->user\U pk;
$winnerMaxBid=$row->MAXDBID;
$ip=$row->ip;
$WINING=$row->WINING;
$qualifyingbid=$currentHighBid*1.01;//下一个允许的出价应该比当前出价高1%
$displayQualifyingBid=number_格式($qualifyingbid,8,'.','');//格式为小数点而非科学符号
}
if($currentWinner==$userid&&$open==0)//修复未定义的
echo“你赢了!祝贺你!”;
//在此处输入付款表格
if($currentWinner==$userid&&$open==1)//修复未定义的
echo“您目前是高出价者。”;
//在此处输入付款表格
if($currentHighBid==NULL)//修复未定义的
回显“项目当前没有出价”;
其他的
echo“当前出价为$currentHighBid BTC”;
如果($open==1)
echo“下一个可接受的出价是$displayQualifyingBid BTC”;
如果($剩余>0)
echo“此项目剩余美元。”;
}
如何确保这些文件被正确转义\消毒?一个有帮助的函数如何
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
函数cleanInput($input){
$search=array(
'@]*?>.@si',//去掉javascript
“@@si”,//去掉HTML标记
“@]*?>.*?@siU”,//条形样式标记正确
'@@'//带多行注释
);
$output=preg_replace($search,,$input);
返回$output;
}
要防止恶意代码注入,请查看。要防止HTML注入,请使用.Don't。理论上你可以使用,但是很容易忘记,如果你只忘记一次,那么你的网站就不安全了。请注意,框架是codeigniter,这对实现有影响吗?
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}