Hi,
I pretty eager about the amazon services using XML to access their catalogue, but all the scripts I've come across using PHP are not working on my server, although the demo is working fine.
Here is the code:
<?php
/*
filename: amazon_class.php
created: 7/17/2002 by Calin Uioreanu
descripton: webservice class definition for Amazon Parser
*/
class Amazon_WebService {
var $sData;
var $arAtribute;
var $iNumResults;
var $sTemplate;
/**
void Amazon_WebService(void)
constructor
*/
function Amazon_WebService()
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, &$this);
xml_set_element_handler($this->parser, 'startHandler', 'endHandler');
xml_set_character_data_handler($this->parser, 'cdataHandler');
} // end func
/**
boolean parse(void)
Short description.
*/
function parse() {
if (!is_resource($this->fp)) {
return false;
}
while ($data = fread($this->fp, 2048)) {
$err = xml_parse($this->parser, $data);
if (!$err) {
fclose($this->fp);
return $err;
}
}
fclose($this->fp);
return true;
} // end func
/**
void startHandler (obj , str , arr)
Event handler called by the expat library when an element's begin tag is encountered.
*/
function startHandler($parser, $sTag, $arAttr) {
// Start with empty sData string.
$this->sData = '';
// Put each attribute into the Data array.
foreach ($arAttr as $Key=> $Val) {
$this->arAtribute["$sTag:$Key"] = trim($Val);
}
}
/**
void cdataHandler (obj, str)
Event handler called by the expat library when Character Data are encountered.
*/
function cdataHandler($parser, $sTag) {
$this->sData .= $sTag;
}
/**
void endHandler (obj, str)
Event handler called by the expat library when an element's end tag is encountered.
*/
function endHandler($parser, $sTag) {
static
$ASIN,
$PRODUCTNAME,
$CATALOG,
$AUTHORS,
$RELEASEDATE,
$MANUFACTURER,
$IMAGEURLSMALL,
$IMAGEURLMEDIUM,
$IMAGEURLLARGE,
$LISTPRICE,
$OURPRICE,
$USEDPRICE
;
// put the $this->sData into a string.
$sData = $this->sData;
switch (strtoupper ($sTag)) {
case 'ASIN':
case 'PRODUCTNAME':
case 'CATALOG':
case 'AUTHORS':
case 'AUTHOR':
case 'RELEASEDATE':
case 'MANUFACTURER':
case 'IMAGEURLSMALL':
case 'IMAGEURLMEDIUM':
case 'IMAGEURLLARGE':
case 'LISTPRICE':
case 'OURPRICE':
case 'USEDPRICE':
$$sTag = $sData;
break;
case 'DETAILS':
$sBookUrl = $this->arAtribute['DETAILS:URL'];
//Details finished
require($this->sTemplate);
// flush the output
flush();
break;
case 'PRODUCTINFO':
//ProductInfo finished
break;
}
}
// }}}
// {{{ setInputUrl()
/**
* Defines
*
* @param string sUrl (full url)
* @param integer iTimeout (url open timeout)
* @return resource fsockopen handle of the given file
* @throws XML_Parser_Error
* @see setInput(), setInputFile()
* @access public
*/
function setInputUrl($sUrl, $iTimeout) {
$arUrl = parse_url($sUrl);
$sHost = $arUrl['host'];
if (!@$iPort = $arUrl['port']) {
$iPort = 80; // default HTTP port
}
$sFullPath = $arUrl['path'] . '?' . $arUrl['query'];
$fp = fsockopen($sHost, $iPort, $errno, $errstr, $iTimeout);
if(!is_resource($fp)) {
// return an error
error_log ("$errstr ($errno)\n");
return false;
} else {
fputs($fp,'GET '. $sFullPath .' HTTP/1.0' . "\n\n");
// win32
if (function_exists('socket_set_timeout')) {
@socket_set_timeout($fp, $iTimeout);
}
// in blocking mode it will wait for data to become available on the socket
socket_set_blocking($fp, true);
// get the first line and determine the answer-code
$sLine = fgets($fp , 1024);
$iCode = preg_replace("/.*(\d\d\d).*/i" , "\\1" , $sLine);
// an error occurred if code is not between 200 and 399
$error = null;
if ($iCode != 200)
{
error_log (' Unexpected code in ' . $sUrl . ":\n" . $sLine);
fclose($fp);
return false;
}
$sHeader = '';
// no error - now determine start of data (skipping header)
while (!feof($fp))
{
$sLine = fgets($fp , 1024);
if (strlen($sLine) < 3)
{
break;
}
}
$this->fp = $fp;
return true;
}
}
} // end class definition WebSearch
?>
The error is:
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/sites/site4/web/Amazon_Services2/amazon_class.php on line 25.
If it is a server error, what would I need to change???
Thanks alot
Mark