php模拟post 提交表单

<?php 
header(‘Content-type: text/html;charset=UTF-8‘);
$action=$_REQUEST[‘action‘];
//获取验证码
if($action==‘ask_reg‘){
$phone=$_REQUEST[‘phone‘];
if(!preg_match(‘/^((13[0-9]{1})|159|153|189)+\d{8}$/‘,$phone)){
	echo json_encode(array("result"=>"phoneError"));
	exit;
}
$arr = array ("phone"=>$phone,"mac"=>"aabbccdreeff");
$data=json_encode($arr);
//$url=‘http://mobile.9797168.com:8080/uc/ask_reg?data={"phone":"15913160604","mac":"aabbccdreeff"}‘;
$url=‘http://mobile.9797168.com:8080/uc/ask_reg‘;
$json_data = postData($url, $data);
echo $json_data; 

}elseif($action==‘usr_reg‘){
	//注册用户
	$phone=$_REQUEST[‘phone‘];
	$nickname=$_REQUEST[‘nickname‘];
	$pswd=$_REQUEST[‘pswd‘];
	$validcode=$_REQUEST[‘validcode‘];
	if(!preg_match(‘/^((13[0-9]{1})|159|153|189)+\d{8}$/‘,$phone)){
		echo json_encode(array("result"=>"phoneError"));
		exit;
	}
	$arr = array (
			"nickname"=>$nickname,
			"phone"=>$phone,
			"pswd"=>$pswd,
			"mac"=>"aabbccdreeff",
			"validcode"=>$validcode
	);
	$data=json_encode($arr);
	$url=‘http://mobile.9797168.com:8080/uc/usr_reg‘;
	$json_data = postData($url, $data);
	
	echo $json_data;
}elseif($action==‘usr_login‘){
 //用户登陆
	$phone=$_REQUEST[‘phone‘];
	$pswd=$_REQUEST[‘pswd‘];
	if(!preg_match(‘/^((13[0-9]{1})|159|153|189)+\d{8}$/‘,$phone)){
		echo json_encode(array("result"=>"phoneError"));
		exit;
	}
	$arr = array (
			"phone"=>$phone,
			"pswd"=>$pswd
	);
	$data=json_encode($arr);
	$url=‘http://mobile.9797168.com:8080/uc/usr_login‘;
	$json_data = postData($url, $data);
	echo $json_data;
}

//curl 模拟提交交
function postData($url, $data)
{
	$ch = curl_init();
	$timeout = 300;
	curl_setopt($ch, CURLOPT_URL, $url);
	//curl_setopt($ch, CURLOPT_REFERER, "http://127.0.0.1/");   //构造来路
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, ‘data=‘.$data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$handles = curl_exec($ch);
	curl_close($ch);
	return $handles;
}
 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。