KayChen

记录技术生活的点点滴滴

0%

PHP POST提交数据

1.封装curl方法:

1
2
3
4
5
6
7
8
9
function curl($url,$post_data){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);//post提交方式
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$data = curl_exec($curl);
return $data;
}

2.使用方法:

1
2
3
4
5
6
7
$url = 'http://www.kaychen.cn/test';
$post_data = array(
'timestamp'=>time(),
'signature'=>$signature,
'user_id'=>1,
);
$data = curl($url,$post_data);