tags:

views:

57

answers:

2

Hi

On my website users can keyword search and find desired results. (Just a simple keyword search, WHERE word LIKE %abc% OR LIKE %cde% etc etc). This all works fine.

I have some partner websites which want to put a search box on their website to search records from my website and display on their website.

We are using PHP and MYSQL. Will the partner websites have to use cURL like softwares? I want it make it minimal but authenticated effort for my partner websites.

So my questions ares - - how do and where to start from? - what changes I'll have to make into my existing search?

  • Any practical examples will definitely help? (PS: I am not looking for complete solution but you know some code does help to understand things a lot)

Thanks all.

+3  A: 

Well you could open your entire MYSQL socket so that they can make direct connections but that would be a terrible solution. So what you probably want to do is to create some kind of simple webservice where another software (like cURL) can retrieve data in a machine readable form (for example JSON or XML). Simply put you just have to serialize your search results into the proper format instead of outputting them to HTML.

<?php

$search = array(
    array("id" => 1, "name" => "An item name", "description" => "The item description"),
    array("id" => 2, "name" => "Another name", "description" => "This is a description")
);

// Of course the array above is just an example. You would probably do something like this:
$search = find_items(mysql_real_escape($_GET['search']));

echo json_encode($search);

?>

The good thing is that you can easily use the same data via AJAX as well.

Daff
either that or iframe the search box.
dusoft
so what happens when search results are in large number?? I mean on my website I have paging functionality .. they need to request per page results?
Wbdvlpr
Well you should can page that request as well and additionally transfer the entire number of records. array("records" => 1000, "per_page" => 100) so $search = find_items(mysql_real_escape($_GET['search']), mysql_real_escape($_GET['page']));
Daff
+1  A: 

cURL would be one way to do it, but a better approach would be to use SOAP in this case. You basically set up an wsdl (xml file) for partner websites to parse and then send appropriate requests to your SOAP service (e.g. authentication + search terms) and then you return the data (e.g. an array of arrays(url, headline, desc)).

With this approach as opposed to cURL is a possible authentication of partner websites and therefore an easy way to determine which partner website generate what search requests et al.

But this is a more complex solution and requires a SOAP extension for PHP (on both sides).

Residuum
if you do not like to mess arround with soap you could use any xml/json microformat you want.
Hippo