Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading information from a web-server

Posted on 2009-04-04
7
Medium Priority
?
164 Views
Last Modified: 2012-05-06
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
Comment
Question by:Andy Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24068179
What value?  From what server?  If you explain a little more maybe we can give some concrete help.

Standing by, ~Ray
0
 

Author Comment

by:Andy Brown
ID: 24068236
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24068276
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.

 

Author Comment

by:Andy Brown
ID: 24068312
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24068390
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
 

Author Closing Comment

by:Andy Brown
ID: 31566611
Thanks Ray - that's  really given me something to work on.  

Really appreciate your help with this one.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24068451
Glad to help.  Thanks for the points! ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question