Login   Register  
PHP Classes
elePHPant
Icontem

File: example1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Keyvan Minoukadeh  >  HTTP Navigator  >  example1.php  >  Download  
File: example1.php
Role: ???
Content type: text/plain
Description: Example file, see http://www.k1m.com/scripts/http_navigator/ for more examples
Class: HTTP Navigator
Web fetching
Author: By
Last change:
Date: 2002-02-12 22:37
Size: 3,134 bytes
 

Contents

Class file image Download
<?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" : ""); ?>> &nbsp; 
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">&nbsp;
<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>