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> <hello@XXXX.com>
	 * @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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.