Location: PHPKode > scripts > http > http/class.http.php
<?php
	/*
		Name:			class.http.php
		Description:	This class handles GET and POST HTTP request methods.
		Author:			Lukas Mestan
		Encoding:		UTF-8
		Date:			2009-01-14
	*/

	class http
	{
		// Function:	get($url, [$vars]);
		// Description:	Requests web page via GET HTTP request passing GET arguments.
		function get($url, $vars = Array(), $body = true)
		{
			$newurl = $this->setvars($vars, $url);
			
			if(!headers_sent())
			{
				header("Location: $newurl");
			}
			else
			{
				if($body) echo "<body>";
				echo "<script>location.href = '$newurl';</script>";
				if($body) echo "</body>";
			}
		}
		
		// Function:	post($url, [$vars]);
		// Description:	Requests web page via POST HTTP request passing POST arguments (JScript required).
		function post($url, $vars = Array(), $body = true)
		{
			if(!$vars) $vars = array();
			$r = md5(rand());
			if($body) echo "<body>";
			echo "<form id=\"post_$r\" action=\"$url\" method=\"post\">";
			foreach($vars as $key => $value)
			{
				if ($value != "") echo "<input type=\"hidden\" name=\"$key\" value=\"$value\">";
			}
			echo "</form>";
			echo "<script>post_$r.submit();</script></body>";
			if($body) echo "</body>";
		}
		
		// Function:	getvars($string, [$array]);
		// Description:	Gets GET arguments from an URL.
		function getvars($string, $array = Array())
		{
			$pattern = "/(\w+)(?:=)([\w%]*)(?:&|$)/";
			$matches = Array();
			
			preg_match_all($pattern, $string, $matches, PREG_SET_ORDER);
			foreach($matches as $match)
			{
				$array[$match[1]] = $match[2];
			}
			
			return $array;
		}
		
		// Function:	setvars($array, [$string]);
		// Description:	Sets GET arguments to an URL.
		function setvars($array, $string = "")
		{
			foreach($array as $key => $value)
			{
				if(preg_match("/(\?|&)($key=)([\w]*)(&|$)/", $string))
				{
					if($value != "")
					{
						$string = preg_replace("/(\?|&)($key=)([\w]*)(&|$|)/i", "$1\${2}$value$4", $string);
					}
					else
					{
						$string = preg_replace("/(\?|&)($key=)([\w]*)(&|$|)/i", "$4", $string);
						if(!strpos($string, "?") && strpos($string, "&"))
						{
							$string = substr($string, 0, strpos($string, "&")) . "?" . substr($string, strpos($string, "&")+1);
						}
					}
				}
				else
				{
					if($value)
					{
						$delimiter = preg_match("/\?/", $string) ? "&" : "?";
						$string = "$string{$delimiter}$key=$value";
					}
				}
			}
			
			return $string;
		}
		
		// Function:	nullnum($num, $digits);
		// Description:	Adds leading zeros to a number.
		function nullnum($num, $digits)
		{
			if (strlen($num) >= $digits)
				return $num;
			
			return str_repeat("0", $digits - strlen($num)) . $num;
		}
	}
?>
Return current item: http