用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

将curl相关操作封装成方法

2016-02-02 作者: baobao举报

[php]代码库

function curl_request($url, $sim = true, $method = "get", $postfields = NULL) {
    $sim or $url .= "&sim_request=1";
    $ci = curl_init ();
    curl_setopt ( $ci, CURLOPT_URL, $url );
    curl_setopt ( $ci, CURLOPT_HEADER, FALSE );
    curl_setopt ( $ci, CURLOPT_RETURNTRANSFER, TRUE );
    curl_setopt ( $ci, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT'] );
    curl_setopt ( $ci, CURLOPT_SSL_VERIFYPEER, 0 );
    curl_setopt ( $ci, CURLOPT_SSL_VERIFYHOST, 0 );

    if ('post' == strtolower ( $method )) {

        curl_setopt ( $ci, CURLOPT_POST, TRUE );
        if (is_array ( $postfields )) {
            $field_str = "";
            foreach ( $postfields as $k => $v ) {
                $field_str .= "&$k=" . urlencode ( $v );
            }
            curl_setopt ( $ci, CURLOPT_POSTFIELDS, $field_str );
        }
    }
    $response = curl_exec ( $ci );
    if (curl_errno ( $ci )) {
        throw new Exception ( curl_error ( $ci ), 0 );
    } else {
        $httpStatusCode = curl_getinfo ( $ci, CURLINFO_HTTP_CODE );
        if (200 !== $httpStatusCode) {
            throw new Exception ( $response, $httpStatusCode );
        }
    }
    curl_close ( $ci );
    return $response;
}

$param=array();
$param['username'] = rtrim($users[$i],"\r");
$param['action']='deleteuser';
$url = $aduseropt_url."/ldapInterface.php";
$res = curl_request($url,true,'post',$param);


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...