I have a site where we have a store locator that uses Mapquest to actually get the data from. We have a vendor that has a site where they want the user to enter a zip code, and it displays the closest 2 stores to the zip code they entered. If the vendors site does not use php, when the user enters a zip code, how do I have them send the zip code to our store locator, get the results, and them send the results back to them?
Thanks!!
fyrestrtr
10-06-2003, 03:17 PM
You can have them send you the zip codes via a get request (the same way you are probably getting the mapquest information).
You then do your calculation, and return to them either an image, or a HTML file with the results.
They can then chose to integrate the file in their website however they like (for example, as an iframe, etc.)
For example, on their end, they would have iframe source like such :
I would recommend that you have them send some unique identifier (or some other way to authorize them), so that other people don't use your zip distance calculator (unless you don't care for that stuff).
If they can use any form of server-side scripting (ASP, JSP, PHP, CFML) ... I would recommend you create a XML service that does the calculation :) But that's just what I would do ... maybe I like to complicate things :P
Hope this helps.
jrthor2
10-07-2003, 07:16 AM
I don't know anything about XML. I figured I'd have them send us the zip codes and do my magic. Do I have to send them a file back though? Can I just populate a variable that has the info in it?
jrthor2
10-07-2003, 08:43 AM
Ok, I have the following function that displays a page with adresses and phone numbers. I need to only show the first 2 though, as right now it displays all the results. I have what I thought would only show the first 2 bolded below, but it doesn't work. Can someone help?
// if we got down here, we got something back from mapquest--now
// figure out what it was
if ($BAD_ADDRESS || $AMBIGUITIES || $NOFOUND || !@count($store_numbers) ) {
$status="Error: No Rite Aid stores found for your query. Please
try again.";
return;
} else {
$stores=fill_store_specs($store_numbers);
}
}
// passed in store_numbers as keyed hash, event_stores as an array for
// results, status as string for result checking
function fill_store_specs($store_numbers) {
$temp_stores=array();
$stores=array();
if (@count($store_numbers) ) {
$sql_stores="";
# build a string for our sql query "IN" clause
for(reset($store_numbers);$key=key($store_numbers);next($store_numbers)) {
$sql_stores.="$key,";
}
# if we've data, remove the last comma
if (strlen($sql_stores)) {
$sql_stores=substr($sql_stores,0,-1);
}
# do database lookup
$D=new mydb;
$sql="select
LOLCN_LOCN,
LOLCN_ADDRESS,
LOLCN_CITY,
LOLCN_STATE,
LOLCN_ZIP,
LOLCN_ZIP4,
LOLCN_RX_AREA_CODE,
LOLCN_RX_EXCHANGE,
LOLCN_RX_EXTENSION,
LOLCN_FX_AREA_CODE,
LOLCN_FX_EXCHANGE,
LOLCN_FX_EXTENSION,
LOLCN_FE_AREA_CODE,
LOLCN_FE_EXCHANGE,
LOLCN_FE_EXTENSION
from sysadm.LOLCN_LOCATION
where LOLCN_LOCN in ($sql_stores)";
$D->my_sel($sql);
if ($D->ORA_ERR ) {
// need to handle errors
handle_ora_error($D,__FILE__,__LINE__);
}
# now create a third hash that is in the same order as the one we
# came in with
if ($D->numrows) {
for(reset($store_numbers);$key=key($store_numbers);next($store_numbers)) {
$stores[$key]=$temp_stores[$key];
}
}
}
return $stores;
} # end fill_store_specs
# ---------------------------------------------------------------------
function check_store_date($stores, $key) {
# ---------------------------------------------------------------------
// passed $stores--a keyed hash of store info and $events, an array of
// store event information
function show_store_results($stores, $events) {
} // end of making sure we're included only once
?>
jrthor2
10-07-2003, 10:01 AM
Nevermind, I got it to show only 2 results, there is a variable in the url to change to how many you want to show. Now that I have this page/data, how do I get it back to the vendors site?
fyrestrtr
10-07-2003, 01:36 PM
The simplest solution would be to just echo the information, and have the vendor include the file in an iframe.
This would appear that the information was coming from the vendor, but its actually coming from your website.
Another option would be to do the reverse ... send them the results via GET, and have them parse the get string and display the information however they like. This would be like a call-back URL that they can specify in their original request, or something that is statically setup in your PHP script. It is the same idea behind most payment processing gateway APIs. You send them the information, along with the URL to a script (or in most cases, your "client id", which the script then checks to figure out what the return URL should be) to which the processor returns the results.
So, your "output" would really be a header() call to their script, with the results as a GET query. Something like :
Again, I would really suggest you look into making this a XML service ... because it will take care of your return/accept data problems for you. The added bonus is that it will return the results as a XML file, which almost everything can read.
You are welcome to email me if you need more help with the xml service bit or some pointers/examples.
jrthor2
10-07-2003, 02:47 PM
Could you give me some xml examples that do this sort of thing, or help with the code for my app? Thanks a lot, you've been a great help!!
fyrestrtr
10-08-2003, 03:49 AM
There is a good tutorial (http://www.devbuilder.org/asp/dev_article.asp?aspid=12) at devbuilder that shows you how to create web services with NuSOAP and PHP. It shows you how to create both the client, and the server.
Let me know if you need more help.
If you are serious about doing this, I would suggest getting an account with mapquest/mappoint/etc.
You will have to pay (there are different models of payment, and with mappoint -- you can get a 90 day trial account), but it gives you direct access to their API, so that you can make proper requests to their mapping engine, and not have to farm their webpage for information.
With mappoint (from MS), you can download their sample clients that can customize the map display, data returned, etc. I was doing the exact same thing you are for a client a few months ago. We used the mappoint trial -- and then decided to use their pay-per-use plan. It worked great. no more farming webpages, having to change your script everytime the webpage layout changed, etc. We got the raw data using (you guessed it, web services) -- and we customized it for our own use.
jrthor2
10-09-2003, 07:30 AM
My company is already licensed to use mapquests software.
jrthor2
10-13-2003, 07:51 AM
Is there a way to not use NuSoap, or any other third party software? I don't have access tou our servers to install this kind of stuff.
Maybe you could help me write the XML, etc for this.
fyrestrtr
10-13-2003, 10:01 AM
Well, you really need to get something like NuSOAP or one of the many PEAR modules to really work with webservices.
Of course you can always roll your own, but that's more work :)
What do you need help with exactly?
jrthor2
10-13-2003, 10:37 AM
Well, I'm not sure, I'm completely new to web services. I went through our code and I developed a page that will give you the 2 closest stores given a zip code (through changing the value in our url). How would I get that info to the outside company (I guess without using web services since I can't install NuSoap or anythinglike that).
Sorry if this is confusing.
fyrestrtr
10-14-2003, 12:43 AM
If you want to do it without web services, here are a few ideas :
1. You can write out the information in a plain text file and stick it on a FTP (or web) server. You would then have to choose the authentication method you want. Either you can create FTP accounts for your clients, or you can provide .htaccess security for a web server.
2. You can also create your own API for getting the information from your script. Here is how that would work. Your clients would send a request to a script that would (a) authenticate them and (b) validate their input. It would then pass this information to your "logic" script which would then calculate the distances, etc. from Mapquest. You can then offer to send them (your clients) back the information to a script on their server.
Your API documentation would describe in detail what kind/type of information the client can send your script, and what kinds of information they can expect in return (ie, a list of error codes, return data types, etc.).
Here is a rediculously simplified example of how this would work.
Say your authentication script is auth.php. You clients would send it information like such :
Then in your auth.php you would verify this information :
include "db.php"; //db functions
$dbObj = new db(); //database object
/* make sure clientid is present */
$client = (isset($_POST['clientid'])) ? $_POST['clientid'] : NULL;
/* get basic client information */
$result = $dbObj->fetchInfo($client);
/* set callback URL from DB */
$callbackURL = $result['cback'];
/* initiate logic script */
Basically you would verify the client's information, then take the data given and forward it to your logic script, which would handle all the calculations, fetching, etc. The callback URL is where you would return the results (usually POST them). This would have to be a script on the client's machine that either you code, or their developer codes so that it knows what to do with the information returned.
On authentication, you can return the distances, store information, etc. practially anything that can be serialized (even and entire array of information).
Installing NuSOAP or any of the PEAR classes isn't a big difficult proposition. You can even do it in a sharing hosting environment.
All you need to do is give the path to the file that contains the classes (for the server). The server "class" is just a file that is avaialable via HTTP. It sits idle until a request is made, and then it performs and operation and returns the results as XML -- something that almost all computer systems can understand.
NuSOAP and PEAR are nothing but php scripts that make it easier to deal with the XML that is generated by web services.
I hope this helps, and best of luck.
jrthor2
10-23-2003, 12:31 PM
I got the nusoap.php file. I have a page that si nothign but functions for our store locator. I put the nusoap required code in this page, and get the following whe I call this page:
<?xml version="1.0" ?>
- <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd">
- <SOAP-ENV:Body>
- <SOAP-ENV:Fault>
<faultcode>Server</faultcode>
<faultactor>method '' not defined in service ''</faultactor>
<faultstring />
<faultdetail />
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I can share my code for this page if needed.
fyrestrtr
10-24-2003, 07:31 AM
You need to define your functions in the service :)
By including the nusoap class, you have made available the server, not you need to give it the functions that you want the server to respond to.
There is a nusoap tutorial at zend that might help you out.
jrthor2
11-18-2003, 08:35 AM
I got sidtracked with some other stuff, but I am still trying to get this to work. I have webservice.php page that has all my function is, and it has this at the top:
/* Include the NuSOAP library. */
require_once('/home/prgjr1/public_html/ra-new/inc/nusoap.php');
/* Create a new SOAP server instance. */
$server = new soap_server;
/* Register the taxCalc function for publication. */
$server->register('find_stores_by_zip');
$server->register('fill_store_specs');
$server->register('check_store_date');
$server->register('show_store_results');
$server->register('format_phone');
$server->register('print_address');
I then have a webservice_client.php page that is the page the user calls, supplying a zip code. If we get any store numbers back, then I run the code below, but I am still getting the "method not defined in service" error when printing the $soapresults.
if (count($stores)) {
//include('nusoap-0.6.1/nusoap.php');
require_once('/home/prgjr1/public_html/ra-new/inc/nusoap.php');
$soapclient = new soapclient('http://rawebdev.rss.riteaid.com/prgjr1/ra-new/stores/locator/webservice.php');
$soapresults = $soapclient->call('fill_store_specs',$store_numbers);
print_r($soapresults);
/* handle any SOAP faults. */
if ($client->fault) {
echo " Error exist";
echo "FAULT: <p>Code: {$soapclient->faultcode}<br />";
echo "String: {$soapclient->faultstring} <br>";
} else {
echo "this is the reponse back from the web services: <br>"; // .$soapresults;
$cnt = count($soapresults);
if ($cnt >0 ) {
for ($i=0; $i < $cnt; $i++) {
echo "value: " .$soapresults[$i] ."<br>";
}
} else { echo "No results came back";
}
}
} else if ($NOFOUND || (!$filtered_count > 0) ) {
print ("<p><font color=#000088><b>
Sorry, no stores found within $miles miles of your zip code.
</b></font></p>\n");
}
jrthor2
11-18-2003, 01:03 PM
here are my updated files, but now I am getting
Warning: Invalid argument supplied for foreach() in /home/prgjr1/public_html/ra-new/inc/nusoap.php on line 3045
UPDATE.........................................................................
i downloaded the newest version of nusoap and I don't get the above error anymore, now I get:
attached are my server page, below is my client code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
include "sitecommon.php";
include "dbconn.php";
include "config.php";
//include('nusoap-0.6.1/nusoap.php');
require_once('/home/prgjr1/public_html/ra-new/inc/nusoap.php');
$soapclient = new soapclient('http://rawebdev.rss.riteaid.com/prgjr1/ra-new/stores/locator/webservice.php');