PHP curl get postコミット関数

744 ワード

getコミット
function getRequest ($url) {
    //   
    $ch = curl_init();
    //    ,  URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //     HTML    
    $output = curl_exec($ch);
    //  curl  
    curl_close($ch);

    return $output;
}

义齿
function postRequest($url, $data) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // post  
    curl_setopt($ch, CURLOPT_POST, 1);
    // post   
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}