• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Reading information from a web-server

I have an Access database, that needs to pull a value in from a web-server.  At present I haven't configured the data-source on the webserver (i can be fairly flexible here).  I just need to know if it can be done.  
0
Andy Brown
Asked:
Andy Brown
  • 4
  • 3
1 Solution
 
Ray PaseurCommented:
What value?  From what server?  If you explain a little more maybe we can give some concrete help.

Standing by, ~Ray
0
 
Andy BrownAuthor Commented:
Cheers Ray (sorry, I've just realised that I should have also added this to the Access zone)

Anyhow - We have a database that is on different sites around the country.  

In this case it is about licensing.  I periodically want the front-end to check a web-server and see if they are still allowed access to run that front-end.  For example, we put a tick box as a field on the server's database (whatever that may be) and if ticked, the front-end will run until the next period.  

This is just one example (and is a very crude explanation) - but it gives you and ideas as to what I want to achieve.

I have a web server, which is hosted for us - and that's about it at present.

I just need a pointer in the right direction.

Thanks again.
0
 
Ray PaseurCommented:
Understood.  What you want to learn about is called the RESTful interface for web services.  Representational State Transfer can be made way complicated by some of the writers on the subject, so let me explain and show you how to find an example.

In a REST query, you put all the information about the query in the URL GET string, including an API KEY that is used as your "password" to use the web service.  You get back a string of information, usually CSV or XML data.  Yahoo has a good example in their GeoCoder manual.
http://developer.yahoo.com/maps/rest/V1/geocode.html

This is different from SOAP, and IMHO much simpler to write and debug.

Does that help point in the right direction? ~Ray
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Andy BrownAuthor Commented:
That seems like the right kind of idea.  I am kind of new to this, I have only just created my first form and PHP script (for a seperate exercise) - so please bare with me (I'm good with VBA but that's about it).





0
 
Ray PaseurCommented:
Drop everything and go buy this book.  If you work thorough the examples, it will put you light years ahead in PHP.  And you can get it in PDF format, so you can start right away.  It is useful as a tutorial and a reference -- a permanent part of my professional library.
http://www.sitepoint.com/books/phpmysql1/

It does not cover REST interface, IIRC, but I can show you a basic REST call.  See the code snippet.  The actual call is at line 81.

HTH, ~Ray
<?php // demo_geocoders.php
//
// DEMONSTRATE CALLING THE YAHOO GEOCODER SERVICE TO GET THE LAT/LON PAIR FOR AN ADDRESS OR PART OF AN ADDRESS
//
// OCTOBER 27, 2008 NOTES
//
// EXECUTIVE SUMMARY - INPUT DATA IN ORDER OF PREFERENCE
//   STREET ADDRESS, CITY, STATE, ZIP+4 LIKE 1446 COLLEEN LN, MCLEAN, VA 22101-3104 = ADDRESS PRECISION
//   STREET ADDRESS, ZIP or ZIP+4 = ADDRESS PRECISION
//   STREET NAME AND ZIP OR ZIP+4 = STREET PRECISION
//   ZIP+4 LIKE 22101-3104 OR JUST ZIP LIKE 20852 = ZIP PRECISION
//
// GOTCHAS
//   YOU MUST PRESENT ZIP+4 LIKE 20016-2375.  IF YOU USE 200162375 YAHOO CANNOT HANDLE IT
//
// ACCURACY EQUIVALENTS
//  YAHOO!    GOOGLE
//  state       2
//  city        3
//  city        4
//  zip         5
//  street      6
//  address     8
//
 
 
// GET THE API KEYS
require_once('_config.php');
 
 
// GET A FREEFORM LOCATION STATEMENT
$loc = '';
foreach ($_GET as $k => $v) { $$k = get_clean_text_string($v); } // LOCAL FUNCTION TO TIDY UP INPUT STRINGS
if ($a != '') { $loc .= $a . ' '; }
if ($c != '') { $loc .= $c . ' '; }
if ($s != '') { $loc .= $s . ' '; }
if ($z != '') { $loc .= $z . ' '; }
$loc = trim($loc);
 
?>
<html><head><title>Address <?=$a?> <?=$c?> <?=$s?> <?=$z?> Yahoo/Google Geocoder Query</title></head>
<body>
<form method="get">
Addr: <input type="text" name="a" autocomplete="off" value="<?=$a?>" />
City: <input type="text" name="c" autocomplete="off" value="<?=$c?>" />
ST:   <input type="text" name="s" autocomplete="off" value="<?=$s?>" size="2" />
Zip:  <input type="text" name="z" autocomplete="off" value="<?=$z?>" size="8" />
<input type="submit" name="_go" value="go" />
</form>
</body>
</html>
<?php
 
 
// IF NO DATA SUBMITTED YET
if (empty($_GET)) { die(); }
 
 
// BASIC URL FOR THE YAHOO CALL
$yahoo_url	= "http://local.yahooapis.com/MapsService/V1/geocode?appid=" . YAHOO_API;
 
/* YOU CAN ASK FOR INDIVIDUAL PIECES OF AN ADDRESS
$yahoo_url	.= "&street=" .	urlencode($a);
$yahoo_url	.= "&city=" .	urlencode($c);
$yahoo_url	.= "&state=" .	urlencode($s);
$yahoo_url	.= "&zip=" .	urlencode($z);
*/
 
// APPEND A FREEFORM QUERY FROM THE PARTS OF A STREET ADDRESS
$yahoo_url	.= "&location=" . urlencode($loc);
 
// SHOW THE QUERY - DO NOT DISPLAY THE API KEY
$yahoo_no_api_url	= str_replace(YAHOO_API, "[YahooAPI]", $yahoo_url);
echo "<h2>Yahoo! Geocoder Query Returns XML</h2>\n";
echo "<h4>ManPage here: <a target=\"_ymp\" href=\"http://developer.yahoo.com/maps/rest/V1/geocode.html\">http://developer.yahoo.com/maps/rest/V1/geocode.html</a><br />\n";
echo "Accuracy Constants here: <a target=\"_ymp\" href=\"http://developer.yahoo.com/maps/rest/V1/geocode.html\">http://developer.yahoo.com/maps/rest/V1/geocode.html</a> (see Response Fields)</h4>\n";
echo "Query String: $yahoo_no_api_url <br />\n";
 
// EXECUTE YAHOO GEOCODER QUERY
// NOTE - USE ERROR SUPPRESSION OR IT WILL BARF UP THE YAHOO API - ON FAILURE RETURNS HTTP 400 BAD REQUEST
if ($fp = @fopen($yahoo_url, 'r'))
{
	while (!feof($fp)) { $y_buf .= fgets($fp); }
	fclose($fp);
}
else
{
	echo "<br />Yahoo Query Failed\n";
}
 
// EXAMINE THE RESULT - NOT EMPTY, WE GOT DATA - CONVERT THE XML TO AN OBJECT
if ($y_buf != '')
{
	$ydata	= new SimpleXMLElement($y_buf);
 
// CHECK FOR ANY ERROR MESSAGE
	$y_err	= $ydata->Message;
// IF NO ERROR MESSAGE, USE THE DATA FROM THE YAHOO OBJECT
	if ($y_err == '')
	{
		$y_qual	= $ydata->Result["precision"];
		$y_warn	= $ydata->Result["warning"];
		$y_lat	= $ydata->Result->Latitude;
		$y_lon	= $ydata->Result->Longitude;
		$y_state= $ydata->Result->State;
		$y_zip	= $ydata->Result->Zip;
 
// NO ERROR MESSAGE, SHOW THE RESULT
		echo "<br />Yahoo Geocoder Result: \n";
		echo "<a target=\"geo_Y\" href=\"http://www.google.com/maps?f=q&hl=en&geocode=&q=" . $y_lat .','. $y_lon . "&ie=UTF8&z=15&iwloc=addr\">$y_lat $y_lon</a><br />Precision=$y_qual \n";
		if ($y_warn != '')
		{
			echo "<br />Warning: $y_warn \n";
			if ($y_state != $s)
			{
				echo "<br />Input State $s does not match Yahoo State $y_state.  Google Data may be better. \n";
			}
		}
	}
	else
 
// THERE WAS AN ERROR IN THE GEOCODER RESPONSE
	{
		echo "<br />Yahoo Geocoder Error: \n";
		echo "$y_err \n";
	}
 
}
else // NO RESULT - SOMETHING IS SICK AT YAHOO
{
	echo "<br />Yahoo! FAIL $y_buf \n";
}
 
// SHOW THE XML FROM YAHOO
$y_buf_p	= ereg_replace('>', ">\n", $y_buf);
echo "<pre>";
echo htmlentities($y_buf_p);
echo "</pre>\n";

Open in new window

0
 
Andy BrownAuthor Commented:
Thanks Ray - that's  really given me something to work on.  

Really appreciate your help with this one.
0
 
Ray PaseurCommented:
Glad to help.  Thanks for the points! ~Ray
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now