php 防注入攻击函数
/*php 防注入函数
string $feifa 限制元素组成
如有非法字符跳转到上一页 返回 0 没有返回 1
*/
//使用方法
//$feifa=array("select","delete","from","update","create","destory","drop","alter","and","or","like","exec","count","*","chr","mid","master","truncate","char","declare",";","-","+");
//$arrpostget=array("http://www.baidu.select cretecomdmin","wangw");
//echo saftsql($feifa,$arrpostget);
function saftsql($feifa,$arrpostget){
//
$arrpostget=array_merge((array)$HTTP_PSOT_VARS,(array)$HTTP_GET_VARS);
if($arrpostget){
foreach($arrpostget as $key=>$value){
for($i=0;$i<count($feifa);$i++){
//找非法字符在$value中的位置
$flag=strpos($value,$feifa[$i]);
if($flag)
{
echo "<script
type=\"text/javascript\">alert('URL有非法字符');</script>";
 
相关文档:
<?php
if($_POST['str'])
{
header('Content-type: application/doc');
header('Content-Disposition: attachment; filename="downloaded.doc"');
echo iconv("UTF-8","GB2312",$_POST['str']);
}
?>
<a href="javascript:void(0)" onclick="downword()">下载</a>
<div id="word" style="dis ......
今天遇到了一个很奇怪的乱码问题,自己无意中解决了,但不知道是什么原因,只好记下来,防止以后再出现这样的问题。
当我把php语句写到下面的页面头信息之前的时候,这些php输出语句都输出的是乱码,包括用echo输出的js。如:echo "<script languge=javascript> alert('添加成功!');location.href = 'device_add.php ......
<?
@session_start();
$counter = intval(file_get_contents("counter.dat"));
if(!$_SESSION['jingyun'])
{
$_SESSION['jingyun'] = true;
$counter++;
$fp = fopen("counter.dat","w");
fwrite($fp, $counter);
fclose($fp);
}
?>
总访问 <span style="font-size:14px; color:#FF6600" mce_sty ......
一. 首先是PHP网页的编码
1. php文件本身的编码与网页的编码应匹配
a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/html; charset=gb2312"),静态页面添加<meta http-equiv="Cont ......
一直认为php中字字符串比较直接用==来判断还是很方便的,但今天遇到的一个问题,彻底让我明白了使用strcmp的必要性.这个问题很多老手都可能会忽略的.
今天在登录自己做的程序时,在输入验证码后,想直接按小键盘上回车登录(程序检查了回车事件),结果按回车按成了键盘上回车键旁边小数的那个键,验证码栏就多输入了一个点。由于 ......