Home > php教程 > PHP源码 > body text

php+json用户注册返回json数据

WBOY
Release: 2016-06-08 17:29:49
Original
961 people have browsed it

下面的一段代码是一段简单的php+json用户注册返回json数据哦,因为在做flash互动时经常会用到flash与json数据交换哦,我们所用php实时返回并且输出json

<script>ec(2);</script>

 require_once("../Inc/Conn.php");
 require_once("../Inc/function.php");
 /*
  接收flash post 数据
  Date"2009.04.24
 */
 
 
 $User_Name = Get_value('User_name',1);
 $User_Pass = Get_value('User_Pass',1);
 $Puser_Pass = Get_value('Puser_Pass',1);
 $User_Mail = Get_value('User_Mail',1);
 $User_Baby_Sex = Get_value('User_Baby_Sex',1);
 $year = Get_value('year',1);
 $month = Get_value('month',1);
 $day = Get_value('day',1);
 $User_Prov = Get_value('User_Prov',1);
 $User_City = Get_value('User_City',1);
 $User_rname = Get_value('User_rname',1);
 $User_Zip = Get_value('User_Zip',1);
 $User_Hand = Get_value('User_Hand',1);
 $User_YesNo = Get_value('User_YesNo',1);
 $User_Address = Get_value('User_Address',1);
 
 if( empty( $User_Name ) || strlen( $User_name ) >8 ){
  
  ShowMsg("{"result":"false"}");
 
 }elseif( empty( $User_Pass ) || ( $User_Pass != $Puser_Pass ) ) {
  
  ShowMsg("{"result":"false"}");
  
 }elseif( !@preg_match("/w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*/",$User_Mail) || strlen($User_Mail)   
  ShowMsg("{"result":"false"}");
 
 }elseif( empty( $User_Prov ) || empty( $User_City ) ){
  
  ShowMsg("{"result":"false"}");
 
 }elseif( !empty( $User_rname ) ){
  
  if( strlen( $User_rname )> 6){
   
   ShowMsg("{"result":"false"}");
   
  }
 }
 if( !empty( $User_Address )){
 
  if( strlen( $User_Address )>100 ){
   
   ShowMsg("{"result":"false"}");
   
  }
  
 }
 
 if( !empty( $User_Zip ) ){  
   
  if( !strlen( $User_Zip )== 6 || !is_numeric( $User_Zip )){
  
   ShowMsg("{"result":"false"}");
  }
  
 }
 if( is_numeric( $User_Hand ) ){
  
  if( !@preg_match("/d{11}/",$User_Hand) ){
   
   ShowMsg("{"result":"false"}");
   
  }
 }
 
 $User_Baby_Birth =@iconv('utf-8','gb2312',"$year 年 $month 月 $day 日");
 
 $sheng = @iconv('utf-8','gb2312',$User_Prov.$User_City);
 
 
 $sql ="Insert into tablename(User_Name,User_Pass,User_Mail,User_Baby_Sex,User_Baby_Birth,sheng,User_Zip,User_Address,";
 
 $sql.="User_Hand,User_YesNo,User_rname) values('$User_Name','$User_Pass','$User_Mail','$User_Baby_Sex','$User_Baby_Birth',";
 
 $sql.="'$sheng','$User_Zip','$User_Address','$User_Hand','$User_YesNo','$User_rname')";
 
 $sqlUser ="select User_Name from tablename where User_Name='$User_Name'";
 
 $result = mysql_query( $sqlUser ) or die(mysql_error().$sqlUser);
 
 if( mysql_num_rows( $result ) ){
  
  ShowMsg("{"result":"false"}");
  
 }else{
  
  if( mysql_query( $sql ) ){
  
   
   $outPut ="{
   "Id":".mysql_insert_id().",n
   "User_Name":"$User_Name",n   
   "User_Mail":"$User_Mail",n
   "User_Baby_Sex":"$User_Baby_Sex",n
   "User_Baby_Birth":"$User_Baby_Birth",n
   "sheng":"$sheng",n
   "User_Zip":"$User_Zip",n
   "User_Address":"$User_Address",n
   "User_Hand":"$User_Hand",n
   "User_YesNo":"$User_YesNo",n
   "User_rname":"$User_rname",n 
   "result":"true" 
   }";
   
   ShowMsg($outPut);
   
 
  }else{
   
   ShowMsg("{"result":"false"}");
   
  }
 
 } 
 
 
?>

本站原创转载注明:  http://www.111cn.net/phper/php.html  

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!