码迷,mamicode.com
首页 > Web开发 > 详细

php模拟post 提交表单

时间:2015-05-22 16:43:50      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:

<?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;
}
 

 

php模拟post 提交表单

标签:

原文地址:http://www.cnblogs.com/vania/p/4522520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!