All pastes #285180 Raw Edit

Untitled

public text v1 · immutable
#285180 ·published 2006-12-19 17:36 UTC
rendered paste body
<?php
/************************************
* Filename: datasock.class.php		*
* Last Modified: 12/19/2006 9:06 AM	*
************************************/
class dataSOCK
{
	private $data;
	private $handle;

	public function __construct($hostname, $data, array $options = NULL)
	{
		//
		// CREATE DATA
		//
		if(is_array($data))
		{
			foreach($data as $key => $value)
			{
				$this->data .= '&' . $key . '=' . urlencode($value);
			}
		}
		else
		{
			$this->data = $data;
		}

		//
		// INITIALISE CURL
		//
		$this->handle = curl_init($hostname);

		//
		// CREATE CURL OPTIONS
		//
		if(is_array($options))
		{
			foreach($options as $key => $value)
			{
				curl_setopt($this->handle, $key, $value);
			}
		}

		//
		// RETURN DATA
		//
		$this->data = curl_exec($this->handle);
		
		//
		// CLOSE CURL CONNECTION
		//
		curl_close($this->handle);
	}

	public function parse()
	{
		if(empty($this->data))
			return false;
		else
			return $this->data;
	}

	public function show_data()
	{
		echo $this->data;
	}
}

$curl = new dataSOCK('MY_HOSTNAME', 'MY_DATA', array('CURLOPT_HEADER' => 0, 'CURLOPT_RETURNTRANSFER' => 1, 'CURLOPT_POSTFIELDS' => array(this, 'data')));

$curl->show_data();

var_dump($curl->parse());
?>