Jump to content

PHP and Curl..............


smazharzaidi

Recommended Posts

Here is CURL wrapper class we wrote. Enjoy.

 

<?php
/**
 * Curl
 * 
	 * @todo
	 *
	 * @version 1.0.2
	 * @date last modified 05/20/2011
	 * @author XXXX <http://www.XXXX.com> <[email protected]>
	 * @copyright (c) 2011 XXXX. All Rights Reserved.
	 */
class Curl {
		private $curl_object;

	public function __construct($p_username = "", $p_password = "", $p_timeout = 10) {
		$this->curl_object = curl_init();	

		curl_setopt($this->curl_object, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json"));
		curl_setopt($this->curl_object, CURLOPT_CONNECTTIMEOUT, $p_timeout);
		curl_setopt($this->curl_object, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($this->curl_object, CURLOPT_SSL_VERIFYPEER, false);

		if(!empty($p_username) && !empty($p_password)) {
			curl_setopt($this->curl_object, CURLOPT_USERPWD, $p_username . ":" . $p_password);
			curl_setopt($this->curl_object, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		}
	}

	public function get_request($p_url) {
		curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
		return curl_exec($this->curl_object);
	}

	public function post_request($p_url, $p_post_data) {
		curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
		curl_setopt($this->curl_object, CURLOPT_POST, true);
		curl_setopt($this->curl_object, CURLOPT_POSTFIELDS, $p_post_data);
		return curl_exec($this->curl_object);
	}

	public function close() {
		curl_close($this->curl_object);
	}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/237194-php-and-curl/#findComment-1218974
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.