Settings | Sign in | Sign up

There are currently 5 posts.

【php】ajax获得参数简写函数

Floor 1 220.221.122.* 12/11/10 14:16

看来php获取ajaxcode编码的参数,用的函数太多了,太混乱了。干脆这样:

//ajax获得参数简写函数
function reajax($name,$code=2,$type=false){
 //$code:0=不编码,1=htmlspecialchars,2=mysql_real_escape_string
 //$type:false=post,true=get
 if ($type){
  $b=$_GET[$name];
 }else{
  $b=$_POST[$name]; //默认
 }
 $b=trim(read_utf8_uns($b));
 switch ($code){
  case 1:
   $b=htmlspecialchars($b);
   break;
  case 2:
   $b=mysql_real_escape_string($b); //默认
   break;
 }
 return $b;
}

Floor 2 220.221.122.* 12/11/10 14:17

mysql_real_escape_string(trim(read_utf8_uns($_POST['b'])))

就可以简写为reajax('b');

Floor 3 220.221.122.* 12/11/10 14:18
还差个unajaxcode……
Floor 4 220.221.122.* 12/11/10 14:19
//ajax获得参数简写函数
function reajax($name,$code=2,$type=false,$nounajaxcode){
 //$code:0=不编码,1=htmlspecialchars,2=mysql_real_escape_string
 //$type:false=post,true=get
 //$nounajaxcode:是否不还原ajaxcode编码
 if ($type){
  $b=$_GET[$name];
 }else{
  $b=$_POST[$name]; //默认
 }
 $b=trim(read_utf8_uns($b));
 if (!$nounajaxcode) $b=unajaxcode($b);
 switch ($code){
  case 1:
   $b=htmlspecialchars($b);
   break;
  case 2:
   $b=mysql_real_escape_string($b); //默认
   break;
 }
 return $b;
}
Floor 5 220.221.122.* 12/11/10 14:22

//ajax获得参数简写函数
function reajax($name='i',$code=2,$type=false,$nounajaxcode){
 //$code:0=不编码,1=htmlspecialchars,2=mysql_real_escape_string
 //$type:false=post,true=get
 //$nounajaxcode:是否不还原ajaxcode编码
 if ($type){
  $b=$_GET[$name];
 }else{
  $b=$_POST[$name]; //默认
 }
 $b=trim(read_utf8_uns($b));
 if (!$nounajaxcode) $b=unajaxcode($b);
 switch ($code){
  case 1:
   $b=htmlspecialchars($b);
   break;
  case 2:
   $b=mysql_real_escape_string($b); //默认
   break;
 }
 return $b;
}

 

现在这三个参数都是可选的。

reajax()≌mysql_real_escape_string(unajaxcode(trim(read_utf8_uns($_POST['i']))))

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.