, released under the GNU GPL //you normally would like to change the following two variables //(but the script should also work as it is) $search ='machiavelli'; //replace this with your own search term, you can give upto 3 terms separated by '%20' like 'cat%20dog', a '+' should also work instad of %20 //$search ='title:"civil+engineering"'; //replace this with your own search term, you can give upto 3 terms separated by '%20' like 'cat%20dog', a '+' should also work instad of %20 $associates_id='chipdir'; //replace this with your own associate id //get one from http://associates.amazon.com/exec/panama/associates/apply //--You don't have to change anything after this line, to start earning money.-- $dev_token='D2WMCOIPS9D14E'; //replace this with your own developer token if you like //get one from http://associates.amazon.com/exec/panama/associates/join/developer/application.html //you don't have to change this token unless you change the code a lot it seems: //http://forums.prospero.com/n/mb/message.asp?webtag=am-assocdevxml&msg=378.1&ctx=0 $mode='books'; //change this if you want to offer something else as books //other modes are: //mode=baby (Baby) //mode=books (Books) //mode=classical (Classical Music) //mode=dvd (DVD) //mode=electronics (Electronics) //mode=garden (Outdoor Living) //mode=kitchen (Kitchen & Housewares) //mode=magazines (Magazines) //mode=music (Popular Music) //mode=pc-hardware (Computers) //mode=photo (Camera & Photo) //mode=software (Software) //mode=tools (Tools & Hardware) //mode=toys (Toys & Games) //mode=vhs (Video) //mode=videogames (Computer & Video Games) # search parameters: $type ='lite'; //don't use this script for the 'heavy' XML! $show_xml=false; //change false to true if you want to see the raw XML data (for debugging) $f_rich =true; //this will convert the URL so you'll get 15% on qualifying books instead of 5%. //change it to false when you prefer to get only 5% ;-) //see http://forums.prospero.com/n/mb/message.asp?webtag=am-assosdev&msg=6.1&ctx=0 //I'm not sure if this method will also work for non-books, but I guess so if (!$page) { $page=1; } $file="onca/xml3?". "dev-t=$dev_token".'&'. "f=xml".'&'. "KeywordSearch=$search".'&'. "mode=$mode".'&'. "page=$page".'&'. // "PowerSearch=$search".'&'. "t=$associates_id".'&'. "type=$type".'&'. "v=1"; //Please note that: //- /onca/xml3 is the pathname of the URL //- ? denotes the spot where the arguments start //- that all arguments consist of 'argument_name=value' and that I have put them in alphabetical order //- that '&' seperates the arguments //you can also add: //- page=1 for result entries 1..10 //- page=2 for result entries 11..20 //- etc. //Each query result will contain only up to 10 entries. If you want to show more than 10 results, you will have to show several pages with results until you get a result with 0..9 entries, but when it's 0 you'll get an error message instead. //To search for ASIN's, replace the KeywordSearch line by AsinSearch=, upto 30 for lite and 10 for heavy searches. //To search for UPC's use instead: UpcSearch=,. //You can also use: //- AuthorSearch =.. (only for mode=books) //- ArtistSearch =.. (only for mode=music,classical) //- ActorSearch =.. (only for mode=dvd,vhs,video) //- DirectorSearch =.. (only for mode=dvd,vhs,video) //- ManufacturerSearch=.. (only for mode=electronics,kitchen,videogames,software,photo,pc-hardware) //- SimilaratiesSearch=ASIN (no mode) //Amazon lists (in the lite version) per book a record like: //
// 039480001X // The Cat in the Hat // Book // // Seuss // Theodor Seuss Geisel // Dr. Seuss // // June, 1957 // Random House (Merchandising) // http://images.amazon.com/images/P/039480001X.01.THUMBZZZ.jpg // http://images.amazon.com/images/P/039480001X.01.MZZZZZZZ.jpg // http://images.amazon.com/images/P/039480001X.01.LZZZZZZZ.jpg // $8.99 // $8.99 // $0.50 //
// //in case there was an error or nothing was found Amazon will return something like: //There are no exact matches for the search. //global variables: $totalresults='unknown'; //get the data from amazon function getAmazon($file) { global $host; global $show_xml; global $totalresults; if ($hf=fopen("http://xml.amazon.com/$file",'r')) { //open a file from Amazon if ($show_xml) { //print the raw XML instead of parsing it into an array? print "
\n";
    }
    while ($line=fgets($hf,10000)) {     //handle each line of XML
      if ($show_xml) {                   //print the raw XML instead of parsing it into an array?
        print   htmlentities(rtrim($line))."\n";
      }
      if      (ereg('HTTP/[0-9]\.[0-9] ([13-9].*)$',$line,$Atmp)) {
        if (!$show_xml) print "HTTP error: ".$Atmp[1]."
\n"; } else if (eregi('(.*)',$line,$Atmp)) { if (!$show_xml) print "Amazon search error: ".$Atmp[1]."
\n"; } else if (eregi('(.*)',$line,$Atmp)) { $totalresults=$Atmp[1]; } else if (eregi('
',$line,$Atmp)) { $E[url]=$Atmp[1]; } else if (eregi("<(.*)>(.*)",$line,$Ares)) { $tag =$Ares[1]; $data=$Ares[2]; if ($tag=='Author') { //there can be multiple authors so put in sub array $E[$tag][]=$data; } else { $E[$tag]=$data; } } else if (eregi("
",$line)) { $A[]=$E; $E=array(); //empty array again } } if ($show_xml) { //print the raw XML instead of parsing it into an array? print "
\n"; } } else die("Can't open socket for xml.amazon.com.
\n"); return $A; } //print the array function printAmazon($A) { global $associates_id; global $f_rich; //do you want 15% or 5%? global $totalresults; //print_array($A); print "
\n"; print "Total number of matches found: $totalresults
\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; while (list($key,$E)=each($A)) { //print out elements if ($E) { //rebuild the URL if you want 15% instead of 5%: $url=$f_rich?'http://www.amazon.com/exec/obidos/ASIN/'.$E[Asin]."/ref=nosim/".$associates_id:$E[url]; print ''; print ''; print ''; print "\n"; } } print "
'; print ""; print ''; print "".$E[ProductName].'
'; print 'by
'; if (is_array($E[Author])) { while (list($kau,$dau)=each($E[Author])) { if ($kau) print ', '; print $dau; } } else print 'UNKNOWN'; print '
'; print '('.$E[OurPrice].')
'; print '
\n"; print "
\n"; } if (false) { //change this to true if you want this debugging info to be shown print "
"; print "Debugging:
\n"; print "Asking Amazon's XML interface for:
\n"; print $file."
\n"; print "
"; } //this is the actual program: //- it reads the data into an array //- prints the array if ($A=getAmazon($file)) { printAmazon($A); } else { if (!$show_xml) { print("No data returned by Amazon.com."); } } print "
\n"; print "\n"; ?>