Fatal error: Cannot redeclare aws_signed_request() (previously declared in /xxx/xxx/public_html/newfunc.php:23) in /xxxxx/xxxxx/public_html/anv4/aws_signed_request.php on line 103
ผมรู้แต่ว้ามันประกาศ function ซ้ำ แต่แก้ยังไงก็ไม่ได้ครับ
code newfunc.php Code (PHP)
<?php
//include("config.php");
$asin = $_GET['go'] ;
$tag=$amazonid ;
if($country=='CA')
{$amazon_c='ca';}
else if ($country=='DE')
{$amazon_c='de';}
else if ($country=='FR')
{$amazon_c='fr';}
else if ($country=='UK')
{$amazon_c='co.uk';}
else if ($country=='JP')
{$amazon_c='co.jp';}
else
{$amazon_c= "com";}
$public_key =$AWSAccessKeyId ; // ??? Access Key ID
$private_key =$SecretAccessKey; // ??? Secret Access Key
function aws_signed_request($region, $params, $public_key, $private_key)
{
// some paramters
$method = "GET";
$host = "ecs.amazonaws.".$region;
$uri = "/onca/xml";
// additional parameters
$params["Service"] = "AWSECommerceService";
$params["AWSAccessKeyId"] = $public_key;
// GMT timestamp
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
// API version
$params["Version"] = "2009-03-31";
// sort the parameters
ksort($params);
// create the canonicalized query
$canonicalized_query = array();
foreach ($params as $param=>$value)
{
$param = str_replace("%7E", "~", rawurlencode($param));
$value = str_replace("%7E", "~", rawurlencode($value));
$canonicalized_query[] = $param."=".$value;
}
$canonicalized_query = implode("&", $canonicalized_query);
// create the string to sign
$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
// calculate HMAC with SHA256 and base64-encoding
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
// encode the signature for the request
$signature = str_replace("%7E", "~", rawurlencode($signature));
// create request
$request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
// do request
$strload = curl_init($request);
curl_setopt($strload, CURLOPT_HEADER, false);
curl_setopt($strload, CURLOPT_RETURNTRANSFER, true);
$response= curl_exec($strload);
curl_close($strload);
if ($response === False)
{
return False;
}
else
{
// parse XML
$pxml = simplexml_load_string($response);
if ($pxml === False)
{
return False; // no xml
}
else
{
return $pxml;
}
}
}
//$parsed_xml= aws_signed_request("$amazon_c", array("Operation"=>"ItemLookup","ItemId"=>"$asin","ResponseGroup"=>"Large","AssociateTag"=>"$tag"), $public_key, $private_key);
$parsed_xml= aws_signed_request("$amazon_c", array("MerchantId" =>"All","Operation"=>"ItemLookup","ItemId"=>"$asin","ResponseGroup"=>"Medium,OfferFull,Offers,OfferSummary,Reviews,MerchantItemAttributes","AssociateTag"=>"$tag"), $public_key, $private_key);
<?php
//20090627/This is a modified version, see the
//return statement some lines before the end of the last function.
function aws_signed_request($region, $params, $public_key, $private_key)
{
/*
Parameters:
$region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)
$params - an array of parameters, eg. array("Operation"=>"ItemLookup",
"ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")
$public_key - your "Access Key ID"
$private_key - your "Secret Access Key"
*/
// some paramters
$method = "GET";
$host = "ecs.amazonaws.".$region;
$uri = "/onca/xml";
// additional parameters
$params["Service"] = "AWSECommerceService";
$params["AWSAccessKeyId"] = $public_key;
// GMT timestamp
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
// API version
$params["Version"] = "2009-03-31";
// sort the parameters
ksort($params);
// create the canonicalized query
$canonicalized_query = array();
foreach ($params as $param=>$value)
{
$param = str_replace("%7E", "~", rawurlencode($param));
$value = str_replace("%7E", "~", rawurlencode($value));
$canonicalized_query[] = $param."=".$value;
}
$canonicalized_query = implode("&", $canonicalized_query);
// create the string to sign
$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
// calculate HMAC with SHA256 and base64-encoding
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
// encode the signature for the request
$signature = str_replace("%7E", "~", rawurlencode($signature));
// create request
$request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
//20090627 and 20090804/Jaap van Ganswijk: I added the next lines
//and commented out the others to prevent getting the file and
//interpreting the XML because my script likes to do that itself.
return $request;
// // do request
// $response = @file_get_contents($request);
//
// if ($response === False)
// {
// return False;
// }
// else
// {
// // parse XML
// $pxml = simplexml_load_string($response);
// if ($pxml === False)
// {
// return False; // no xml
// }
// else
// {
// return $pxml;
// }
// }
}
?>
Date :
2010-12-02 12:53:11
By :
jackcools
No. 2
Guest
ชื่อ function มันซ้ำกันหรือเปล่าครับ ลองเปลี่ยนชื่อ function ดู
อันนี้เป็น code ไฟล์ amazonv4.php บางส่วนครับ ที่ include aws_signed_request.php Code (PHP)
<?php
//amazonv4.php
//stand-alone PHP example script to use the Amazon Web Services interface
//20020816/JvG, released under the GNU GPL
//20030203/JvG, adapted for the heavy version
//20030630/JvG, adapted further
//20030717/JvG, expanded further, this will be released as amazonh3.php
//20030912/JvG, fixed the 'register global' issue that a lot of people had trouble with
//20030912/JvG, found an excessive ' that caused trouble remembering the product category
//20030912/JvG, turned $pagefr0 back into $page (so base 1 instead of base 0, makes script clearer)
//20030912/JvG, tried to explain the associate ID issue better
//20030912/JvG, in case of the UK locale I show the USA product categories, which looks slightly better
//20030912/JvG, in data.php I have disabled Japan, because the script can't really support it
//20030912/JvG, in language.php I fixed a spelling mistake in 'buecher USA'
//20031125/JvG, commented out the hidden language and locale fields in the form
//20040129/Ted Knudson remarked that looking for things like 'kitchen design' didn't work properly and so I added urlencode() at three places in the script
//20040202/Tatiana Vygurska found some errors:
//20040202/JvG, turned $pagefr0 back to $page in the link to the previous page
//20040202/JvG, declared $locale global in function printProduct()!
//20040408/JvG, removed the v=2.1 parameter
//20040715/JvG, added some suggestions by Wim Roffel
//20041207/JvG, utf8_decode() is now executed before interpreting the XML as someone suggested
//20041219/JvG, added a couple of lines of code to print the time used to get data from Amazon and handling it
//20050118/JvG, tried if the script would also easily work with version 4
//20090623/JvG, busy adding the signing that Amazon requires from 20090815
//20090804/JvG, refixed the do/du problem for used products (which had gone after going back to an old version) and added the (server) locale functionality to the signed version
//20090804/JvG, rewrote the scripts to make the new version (with signing) more like the old version so that the caching would work again but didn't test it yet, this also made show_url work again
//20090812/JvG, added the comments for 20090804 and 20090812 and tested the caching and I am going to try to put the script online
//20090816/JvG, always use signed request, started adding better time measurement
//Thanks for all the questions, improvement tips and help!
//Feel free to send more feedback to me at [email protected]!
//Please mention Amazon in the subject line to avoid my spamfilters
$microtime_init0=$microtime0=getmicrotime(); //time at start and before initializing
$jaap=false; //I use this flag to print debugging information about things I am busy with at the moment, you can always change this into false when it isn't already
//set these to correspond with your site
//the user can overrule them
$Adefault=array(
'language' =>'en', //what language to render the page in
'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us
//'mode' =>'books', //what product category?
'page' =>1, //first page to show (we are using base-1 not base-0)
//'search' =>'Machiavelli', //what to search for?
'operation' =>'ItemSearch', //what to do?
'searchindex' =>$cat, //what product category for search?
'searchparameter' =>'Keywords', //what kind of search?
'searchparameterdata'=>$keywords,//$_GET['q'] //what to search for?
//here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending
'show_url' =>false, //debug: show XML request url to be send to Amazon?
'show_xml' =>false, //debug: show incoming XML code from Amazon?
);
//change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
include "data.php"; //static data about Amazon (servers, search fields) v3-
include "data_v4.php"; //static data about Amazon (servers, search fields) v4+
include "language.php"; //translate the output to the prefered language of the user
include "xml.php"; //interpret XML-data
require_once "aws_signed_request.php"; //see: http://mierendo.com/software/aws_signed_query/, please note that I'm using an slightly adapted version of the script: I do my own XML-interpreting
//20090624: the following isn't relevant anymore it seems:
//$Aassociates_id=array(
// 'de'=>'chipdir00' , // <-- replace with your amazon.de associate ID, or leave it as it is
// 'fr'=>'chipdir010', // <-- replace with your amazon.fr associate ID, or leave it as it is
// 'jp'=>'INVALID' , // <-- replace with your amazon.co.jp associate ID, or leave it as it is
// 'uk'=>'chipdir03' , // <-- replace with your amazon.co.uk associate ID, or leave it as it is
// 'us'=>'chipdir' , // <-- replace with your amazon.com associate ID
//);
//20090623: The signed request version requires these two parameters:
//$public_key="xxxxxx"; //you have to get this from Amazon on page https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
//$private_key="xxxxxx"; //you have to get this from Amazon on page https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key
$public_key =$AWSAccessKeyId ;
$private_key=$SecretAccessKey;
//other flags:
//this doesn't seem to be relevant anymore:
//$f_rich=true; //when set to true this will convert the URL so you'll get 7.5% on qualifying books instead of 5%. It doesn't work yet outside of the USA.
//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, or search the forum for 'nosim'
//This is only helpful for certain books
//correction: keep this option set to true, to prevent the showing of Amazon's annoying distraction pages.
//20080530: i don't know if this is still relevant for version 4
$f_user_search=true; //add a user search form and allow user searches?
//=============================================================================
//==You don't have to change anything below this line to start earning money.==
//=============================================================================
if ($jaap) {
print_array($_GET);
}
//what are the user's prefered languages?
$Ahttp_lang=split(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
if ($jaap) {
print_array($Ahttp_lang);
}
//try to find the visitor's prefered language, this is still experimental
foreach ($Ahttp_lang as $i=>$d) {
if ($Axl[$l=substr($d,0,2)]) {
$pref_lang=$l;
break;
}
}
$Adefault['language']=$pref_lang;
if ($jaap) {
echo "prefered available language='$pref_lang'<br />\n";
print_array($Ahttp_lang);
}
//for all parameters see if the user has overruled it or use the default
foreach ($Adefault as $i=>$d) {
$$i=$_GET[$i]?$_GET[$i]:$d;
if ($jaap) echo "$i = '".$$i."'<br />\n";
}
//use which servers?
$norserver=$Aserver[$locale]['nor'];
$xmlserver=$Aserver[$locale]['xml'];
//20090817: this is no longer used it seems:
//$dev_token='D2WMCOIPS9D14E';
//you can replace this with your own developer token after you have changed the script a lot
//get one from http://associates.amazon.com/exec/panama/associates/join/developer/application.html
//see:
//http://forums.prospero.com/n/mb/message.asp?webtag=am-assocdevxml&msg=378.1&ctx=0
//form the URL to send to Amazon as a search request
//this is the part that is search specific
$parameters=array(
'Operation' =>'ItemSearch' ,
'Keywords' =>urlencode($search) ,
'SearchIndex' =>$searchindex , //Books for example.
"BrowseNode" =>$node ,
"$searchparameter"=>$searchparameterdata ,
'ItemPage' =>$page , //which page?
//'Service' =>'AWSECommerceService' , //this makes it version 4
//'SubscriptionId' =>$subscriptionid , //is this correct?
//'AWSAccessKeyId' =>$awsaccesskeyid , //is this correct?
'AssociateTag' =>$amazonid ,
'ResponseGroup' =>'Medium,Reviews' , //Small, Medium or Large
);
$ext=$Aserver[$locale]['ext']; //extension of server, see data.php
$file_data=$ext;
ksort($parameters);
foreach ($parameters as $i=>$d) {
$file_data.='&'.$i.'='.$d;
}
$file=aws_signed_request($ext,$parameters,$public_key,$private_key);