<?php
// choose random site
srand((float)microtime() * 10000000);
$site = array("http://www.amazon.co.uk", "http://www.bbc.co.uk", "http://cnn.com", "http://uk.php.net", "http://www.disney.com");
$rand_site = $site[array_rand($site)];
// set form vars
$url = (!empty($HTTP_GET_VARS["url"]) ? $HTTP_GET_VARS["url"] : $rand_site);
$use_curl = (!empty($HTTP_GET_VARS["use_curl"]) ? true : false);
$use_curl_ssl = (!empty($HTTP_GET_VARS["use_curl_ssl"]) ? true : false);
?>
<html>
<head>
<title>HTTP Navigator - Example 1</title>
</head>
<body>
<h2>HTTP Navigator - Example 1</h2>
<form method="get">
Use cURL <input type="checkbox" name="use_curl" value="yes" <?php echo ($use_curl ? "checked" : ""); ?>>   
Use cURL for SSL <input type="checkbox" name="use_curl_ssl" value="yes" <?php echo ($use_curl_ssl ? "checked" : ""); ?>>
<br>
URL: <input type="text" name="url" value="<?php echo $url; ?>" size="35"> 
<input type="submit" name="submit" value="Go!">
</form>
<?php
// HTTP Navigator example file
// include the class file
require_once("class.http_navigator.php");
// create instance of class
$http = new http_navigator;
// set debug on
$http->set_var("debug", true);
// set cURL settings (based on form checkboxes)
$http->set_var("use_curl", $use_curl);
$http->set_var("use_curl_ssl", $use_curl_ssl);
// grab page
$result = $http->get_url("$url");
echo "<pre>";
// if error or warning
if ($http->is_error($result)) {
	echo "<b>Error: $result[error]</b>";
	echo "</pre></body></html>";
	exit;
} elseif ($http->is_warning($result)) {
	echo "<b>Warning: $result[error]</b>";
}
if ($result) {
	// get status info
	$status = $http->status_info($http->get_status());
	echo '
-----------------------------------------------------
<b>Last Request:</b>
Time taken: '.$http->get_info('time_taken').'
Status Code: '.$http->get_status().'
Status Txt: '.$status['meaning'].'
Status Meaning: '.$status['range_meaning'].'
Body Size: '.$http->get_body_size().'
-----------------------------------------------------
	';
	/////////////////
	// list headers
	/////////////////
	echo "\n<b>Last Header Returned:</b>\n".$http->get_headers();
}
$cookie = &$http->get_var("cookie");
echo "\n\n<b>Cookies Found:</b>\n";
if (count($cookie) == 0) {
	echo "<i>None</i>\n\n";
} else {
	////////////////
	// list cookies
	////////////////
	// loop through domains
	foreach ($cookie as $domain => $domain_val) {
		echo "Domain: $domain\n";
		// looop through path
		foreach ($domain_val as $path => $path_val) {
			echo "	Path: $path\n";
			// loop through name
			foreach ($path_val as $name => $name_val) {
				echo "		Cookie: $name\n";
				echo "		Value: $name_val[value]\n";
				if (isset($name_val["expires"])) {
					echo "		Expires: ".date("D jS M Y H:i:s", $name_val["expires"])."\n";
				} else {
					echo "		Expires: <i>session</i>\n";
				}
				if ($name_val["secure"]) {
					echo "		Secure: Yes\n\n";
				} else {
					echo "		Secure: No\n\n";
				}
			}
		}
	}
}
?>
</pre>
</body>
</html> 
  |