//防SQL注人函数
function FunReplace($str)
{
$strResult = $str;
if(!get_magic_quotes_gpc())//判断设置是否开启
{
$strResult = addslashes($strResult);//转换sql语句特殊字符
}
return $strResult;
}
//URL地址重写
function MakeUrl($arr)
{
foreach($arr as $key=>$value)
{
$url[]=$key."/".$value;
}
$tmpurl=implode("/",$url);
return $tmpurl.".htm";
}
//分析url地址 调用$_get[]获取传过来的值
function ParseUrl()
{
if($_SERVER['PATH_INFO']!="")
{
$pathinfo=substr($_SERVER['PATH_INFO'],1);
$pathinfo=str_replace(".htm","",$pathinfo);//去掉.htm
$path=explode("/",$pathinfo);
$count=count($path);
for($i=0;$i<$count;$i+=2)
{
$_GET[$path[$i]]=$path[$i+1];
}
}
}
function DateDiff($d1,$d2="")
{
if(is_string($d1))$d1=strtotime($d1);
if(is_string($d2))$d2=strtotime($d2);
return ($d2-$d1)/86400;
} //返回值为相差的天数
//php操作access文件
$conn=new com("adodb.connection");
$conn->open("driver=microsoft access driver (*.mdb);dbq=member.mdb");
$rs=$conn->execute("select * from tablename");
while(! $rs->eof) {
$f = $rs->Fields("username");
echo $f->value;
$rs->MoveNext();
}
$rs->close();
$conn->execute("update tablename set username='williamlong' ");
---防注入第2版--
<?php
/*************************
说明:
判断传递的变量中是否含有非法字符
如$_POST、$_GET
功能:
防注入
**************************/
//要过滤的非法字符
$ArrFiltrate=array("'",";","union","or","and","/");
//出错后要跳转的url,不填则默认前一页
$StrGoUrl="";
//是否存在数组中的值
function FunStringExist($StrFiltrate,$ArrFiltrate){
foreach ($ArrFiltrate as $key=>$value){
if (eregi($value,$StrFiltrate)){
return true;
}
}
return false;
}
//合并$_POST 和 $_GET
if(function_exists(array_merge)){
$ArrPostAndGet=array_merge($HTTP_POST_VARS,$HTTP_GET_VARS);
}else{
foreach($HTTP_POST_VARS as $key=>$value){
$ArrPostAndGet[]=$value;
}
foreach($HTTP_GET_VARS as $key=>$value){
$ArrPostAndGet[]=$value;
}
}
//验证开始
foreach($ArrPostAndGet as $key=>$value){
if (FunStringExist($value,$ArrFiltrate)){
echo "<script language=\"javas
if (empty($StrGoUrl)){
echo "<script language=\"javas
}else{
echo "<script language=\"javas
}
exit;
}
}
?>