Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
optivader
Forum Newbie
Posts: 4
Joined: Wed Sep 30, 2009 4:32 pm

Question

Post by optivader »

Hello guys, girls,

I would like to know if it is possible to have a search form on website A that would search site B using site B's search Bar. Example : If I type "apple" on Site A and press Search, could the results for the search "apple" through hobbytron.com open in a new window. I sincerely have no clue if this can be done.

thanks

vader vader
peterjwest
Forum Commoner
Posts: 63
Joined: Tue Aug 04, 2009 1:06 pm

Re: Question

Post by peterjwest »

Lets use an example: imagine you want to use your site, http://www.buystuff.com, to search http://www.amazon.com. The user can enter search terms into a search bar on your site.

Do you want to display the search results on your site or on amazon? If the answer is amazon then its fairly straightforward, you just need to redirect the browser to the appropriate URL on amazon:
header( "Location: http://www.amazon.com/s/ref=nb_ss?$searchTerms" );
where $searchTerms will be something like:
$searchTerms = "?search=wireless+router+netgear"

You'll need to know the search format for the site. For amazon you can use something like:
header( "http://www.amazon.co.uk/s/ref=nb_ss?url ... tr_replace(' ','+',$searchTerms));
This is very crude, you should probably filter the search terms to be URL characters only, among other things.

If you want to display the results on your site it's more complicated.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Question

Post by cpetercarter »

Adding a google search box to a web site is very easy - see for example http://www.askdavetaylor.com/how_can_i_add_a_google_search_box_to_my_web_site.html. You will see that you can limit the search to a single site by means of an input value "sitesearch". Normally folk use this to create a search facility for their own site, but it can equally well be used for searching a different site (provided, of course, that google has been able to index it).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Question

Post by califdon »

optivader wrote:Hello guys, girls,

I would like to know if it is possible to have a search form on website A that would search site B using site B's search Bar. Example : If I type "apple" on Site A and press Search, could the results for the search "apple" through hobbytron.com open in a new window. I sincerely have no clue if this can be done.

thanks

vader vader
Be sure you understand that doing this without the permission of site B may subject you to a lawsuit by site B, whose owners may consider the content and operation of their site as their property.
optivader
Forum Newbie
Posts: 4
Joined: Wed Sep 30, 2009 4:32 pm

Re: Question

Post by optivader »

Thaaaaanks guys for the quick reply.

For your information, I plan on displaying the results within their original website. I will not appropriate the results on my website.

With respect to the Amazon example, I understand that it should be fairly easy, however, some website (hobbytron.com for example, and every website managed with drupal and others) will not have a distinct url for each search.

hobbytron for instance will return "hobbytron.com/search/index.php" whether the search was apple or orange. It's the mechanism behind this type of search bar that I would like to understand.

Thanks to all

vader vader
optivader
Forum Newbie
Posts: 4
Joined: Wed Sep 30, 2009 4:32 pm

Re: Question

Post by optivader »

Any ideas ?

Thanks
peterjwest
Forum Commoner
Posts: 63
Joined: Tue Aug 04, 2009 1:06 pm

Re: Question

Post by peterjwest »

hobbytron for instance will return "hobbytron.com/search/index.php" whether the search was apple or orange. It's the mechanism behind this type of search bar that I would like to understand.
That's because the search information is sent using POST, which is invisible to the URL. An easy way to do this would be to use a form with method POST to send the correct info to the other website. For example:

Code: Select all

<form method="post" action="http://www.hobbytron.com/search/index.php"> 
<input type="text" name="terms"/>
<input type="submit" value="Search!"/>
</form>
You'll need to see what inputs the particular website used, the easiest way to do this would be to inspect the source code of the website's search form.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Question

Post by jackpf »

Don't know if this has come up already, but you could use an iframe. Or cURL.

Or even AJAX.
optivader
Forum Newbie
Posts: 4
Joined: Wed Sep 30, 2009 4:32 pm

Re: Question

Post by optivader »

Many thanks for the help guys,

I will look into it in details
Post Reply