asp防sql注入源程序
<%
squery=lcase(Request.ServerVariables("QUERY_STRING"))
sURL=lcase(Request.ServerVariables("HTTP_HOST"))
SQL_injdata =":|;|>|<|--|sp_|xp_||dir|cmd|^|(|)|+|$|'|copy|format|and|exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
For SQL_Data=0 To Ubound(SQL_inj)
if instr(squery&sURL,Sql_Inj(Sql_DATA))>0 Then
Response.Write "您的操作可能是SQL注入行为。"
Response.end
end if
next
%>
我自己觉得还有防sql注入的方法,那就是用trim()函数,去除所有querystring过来的值的空格,因为sql执行必须带有空格哦,还有如果是id类型的判断是否为数字就OK了。
php简单数据保存程序
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="cname" />
</label>
<p>
<label>
<input type="text" name="caddress" />
</label>
<label>
<input type="text" name="ctel" />
</label>
<label>
<input type="text" name="cfix" />
</label>
<label>
<input type="text" name="cmail" />
</label>
</p>
</form>
<?php
include(dirname(__FILE__).'./inc/gg_function.php');
if( $_POST)
{
$_cname = Get_value('cname',1);
$_address = Get_value('caddress',1);
$_tel = Get_value('ctel',1);
$_fix = Get_value('cfix',1);
$_mail = Get_value('cmail',1);
if( empty($_cname) || strlen( $_cname )>200 )
{
ShowMsg('请输入公司名称!');
}
elseif( empty( $_address ) || strlen( $_address )>200 )
{
ShowMsg('请输入公司地址!');
}
elseif( empty( $_tel ) || strlen($_tel)>12 )
{
ShowMsg('请输入正确的电话号码');
}
elseif( empty($_fix) || strlen( $_fix )>20 )
{
ShowMsg('输入传真号');
}
elseif( empty( $_mail ) || strlen( $_mail )>254 )
{
ShowMsg('输入正确的邮件地址');
}
else{
$_sql = "Insert into gx_coo(c_name,c_address,c_tel,c_fix,c_maile)value('$_cname','$_address','$_tel','$_fix','$_mail')";
if( mysql_query( $_sql ) )
{
ShowMsg('信息保存成功!');
}
else
{
ShowMsg('操作失败请重试一次!');
}
}
}
?>
//==防注入自动过滤[启用后程序效率低]==========================================================================================
/*
function inject_checks($sql_str){return eregi('select|insert|update|delete|'|/*|*|../|./|union|into|load_file|outfile', $sql_str);}
foreach ($_REQUEST as $value){if (inject_checks($value)){echo "<script language=javascript>alert('你提交的数据非法,请检查后重新提交!');</script>";exit;}}
*/
//==防注[inject_check($sql_str)]==========================================================================================
function inject_check($sql_str){
if (eregi('select|insert|update|delete|union|into|load_file|outfile', $sql_str)){echo "<script language=javascript>alert('你提交的数据非法,请检查后重新提交!');</script>";exit;}
return $sql_str;
}
//==字符过滤[safe_convert($string)]==============================================================================
function safe_convert($string){ //Words Filter
if(get_magic_quotes_gpc()){ //转义字符 加上反斜线
$string=htmlspecialchars($string, ENT_QUOTES); //将特殊字元转成HTML字串格式如 "&"转成"&"
$string=str_replace("<","<",$string); //替换
$string=str_replace(">",">",$string); //替换
$string=str_replace("\", '\', $string); //替换
} else {
$string=addslashes($string); //转义字符 加上反斜线 //$string=stripslashes($string); //去掉反斜线
$string=str_replace("\\", '\', $string);
}
//$string=str_replace("r","<br/>",$string); //换行
//$string=str_replace("n","",$string); //空格
$string=str_replace("t"," ",$string); //空格
$string=str_replace(" "," ",$string); //空格
//$string=str_replace('|', '|', $string); //替换 同分类系统有冲突
$string=str_replace("&#96;","`",$string); //替换
$string=str_replace("&#92;","\",$string); //替换
return $string;
}
//==字符反过滤[unsafe_convert($string)]==============================================================================
function unsafe_convert($string){ //Words Filter
$string=str_replace("\"",""",$string); //替换
return $string;
}
//==字符过滤[filter($string)]============================================================================================
function filter($string){ //Words Filter
include("Filter.php");//词汇过滤列表
foreach($badwords as $badword){
if(stristr($string,$badword)==true){echo "<script language=javascript>alert('警告:你提交的内容含有敏感字眼,请更换内容。');</script>";exit;}
}
return $string;
}
你的网页是不是经常被无故的在php,asp,html,js 等文件后台加上一些木马地址呢?我以前有个站就是这样,所以一恨之下写了这段代码,文章虽然有一点浪费资源了,但是总比我们手动清除要好吧,下面我为讲讲程序的清除病毒的原理吧.
首先们要读取 $checkFile 文件这个文章是判断一个文章 是否被感染了,如果是就会执行$savafile变量里面的txt文件路径的所有文件,进行按你infecFile病毒列表清除一次.
<?php
Class clear_virus{
//public $content;
public $infectFile ='virus.txt';//病毒文件列表文件
public $savefile ="save.txt";//所在查看病毒的文件列表
public $timep ='time.txt';//些记录清除病毒时间
public $checkFile ='e.php';//这里是设置
public $run =0;
public $virus_type;
public $replace ;
public $filepath ;
public $tag =0;
function open_file(){
$this->read_virus();
$this->check_File();
if($this->run){
$this->update_time();
$this->read_file() ;
foreach($this->filepath as $tmppath){
if(file_exists($tmppath)){
$tmp_file =file_get_contents($tmppath);
print_r( $this->virus_type);
for( $i=0;$i<sizeof($this->virus_type);$i++ ){
if( strrpos($tmp_file,$this->virus_type[$i])!== false){
$tmp_file =str_replace($this->virus_type[$i],'',$tmp_file);
$this->tag =1;
}
}
if( $this->tag ){
$handle =fopen($tmppath,'w');
fwrite($handle,$tmp_file);
fclose($handle);
unset($tmp_file);
}
}else{
;
}
}
}
}
function check_File(){
if(file_exists($this->checkFile) ){
$temp =file_get_contents($this->checkFile) ;
echo $temp;
foreach( $this->virus_type as $v_tmp ){
if( strrpos($temp,$v_tmp)!== false ){
$this->run =1;
break;
}
}
echo $this->run;
unset($temp);
}else{
$this->show_error(5);
}
}
function update_time(){
if(file_exists($this->timep) ){
$tmp_time =date("Y-m-d H:i:s").chr(13).'|';
$tmp_fp =fopen($this->timep,'a+');
fwrite($tmp_fp,$tmp_time);
fclose($tmp_fp);
}
}
function read_File(){
if(file_exists($this->savefile) ){
$this->content =file($this->savefile);
if(is_array($this->content)){
$this->filepath =$this->content;
}else{
$this->show_error(3);
}
}else{
$this->show_error(4);
}
}
function read_virus(){
if(file_exists($this->infectFile) ){
$this->replace =file($this->infectFile);
if(is_array($this->replace)){
$this->virus_type=$this->replace;
}else{
$this->show_error(1);
}
}else{
$this->show_error(2);
}
}
function show_error($number){
$array = array(
'1'=>'病毒文件未不能读取!',
'2'=>'病毒文件列表不存在!',
'3'=>'文件列表不存了',
'4'=>'查杀的文件不存',
'5'=>$this->$checkFile.'不存在了,请设置病毒感染文件'
);
echo $array[$number];
}
}
$virus =new clear_virus;
$virus->open_file();
?>
最后申明本站原创转请注明来自www.111cn.net/phper/php.html
超简单的php图片统计器,这种统计器以前我是用txt文件做的,现在就直接用数据库实现吧.先来看看数据结构吧.
CREATE TABLE `count` (
`id` int(10) NOT NULL auto_increment,
`value` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=98 ;
好数据准备好了下面我们来看看程序是怎么实现的吧.
<?php
//浏览页面时加入一条记录,从而达到访问加1.
$conn=mysql_connect("localhost","root","root");
//echo mysql_error();
mysql_query("set names gb2312");
mysql_select_db("guest");
$sql="INSERT INTO `count` ( `id` , `value` ) VALUES ('', '32')";
$result=mysql_query($sql);
if ($result) {
echo "插入成功.";
}
mysql_close($conn);
//读出记录数据count(*)
$conn=mysql_connect("localhost","root","root");
//echo mysql_error();
mysql_query("set names gb2312");
mysql_select_db("guest");
$mysql="select * from `count`";
$result=mysql_query($mysql);
$row=mysql_num_rows($result);
for($i=0;$i<strlen($row);$i++)
{
$a=substr($row,$i,1);
$str.= "<img src= "images/$a.jpg" width="32" height="32" />";
}
?>
<div align="center" class="STYLE1">页面总共有<?php echo $str; ?>个人浏览</div>
嗯,php代码写得有一点乱喽,但工能还是能实现的吧.
相关文章
- PHPEMS(PHP Exam Management System)在线模拟考试系统基于PHP+Mysql开发,主要用于搭建模拟考试平台,支持多种题型和展现方式,是国内首款支持题冒题和自动评分与教师评分相...2016-11-25
- SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作 标准注入语句1.判...2016-11-25
- 这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
- 防止SQL注入是我们程序开发人员必须要做的事情了,今天我们就来看一篇关于PHP防止SQL注入的例子了,具体的实现防过滤语句可以参考下面来看看吧。 使用prepared以及参...2016-11-25
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
- 大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 这篇文章主要介绍了Python爬取微信小程序通用方法代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
- 这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25
- 本文主要介绍AngularJS 依赖注入的知识,这里整理了相关的基础知识,并附示例代码和实现效果图,有兴趣的小伙伴可以参考下...2016-08-24
- 这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
- 这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19