?
Solved

Reading information from a web-server

Posted on 2009-04-04
7
Medium Priority
?
163 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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

801 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