$url = '127.0.0.1/shang/bb.php';
$data = array('name'=>'赵猛','age'=>'23');
print_r(get($url,$data)) ;
function post($url,$data = array()){
$query = make_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$totalline = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);
}
curl_close($curl);
return $totalline;
}
function get($url,$data = array()){
$query = make_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url.'?'.$query);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$totalline = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);
}
curl_close($curl);
return $totalline;
}
function make_query($data = array()){
$str = '';
if(!empty($data) && is_array($data)){
foreach($data as $k => $v){
if($str !== ''){
$str .= '&';
}
$str .= $k.'='.urlencode($v);
}
}
return $str;
}