Solved

Reading information from a web-server

Posted on 2009-04-04
7
156 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
  • 4
  • 3
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Andy Brown
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
Thanks Ray - that's  really given me something to work on.  

Really appreciate your help with this one.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Glad to help.  Thanks for the points! ~Ray
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now