Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > ช่วยหน่อยครับ ผมมีเรื่องปัญหา Cannot redeclare aws_signed_request() แก้ไม่ได้ครับ ช่วยหน่อยครับ


[PHP] ช่วยหน่อยครับ ผมมีเรื่องปัญหา Cannot redeclare aws_signed_request() แก้ไม่ได้ครับ ช่วยหน่อยครับ

 
Topic : 052555



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์



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)
01.<?php
02.//include("config.php");
03.    $asin = $_GET['go'] ;
04.     
05.     
06.   $tag=$amazonid ;
07. 
08.      if($country=='CA')
09.                  {$amazon_c='ca';}
10.      else if ($country=='DE')
11.                    {$amazon_c='de';}
12.      else if ($country=='FR')     
13.              {$amazon_c='fr';}
14.       else if ($country=='UK')     
15.              {$amazon_c='co.uk';}
16.       else if ($country=='JP')     
17.              {$amazon_c='co.jp';}
18.      else      
19.{$amazon_c= "com";}
20. 
21.        $public_key  =$AWSAccessKeyId  ; // ??? Access Key ID
22.        $private_key =$SecretAccessKey; // ??? Secret Access Key
23.function aws_signed_request($region, $params, $public_key, $private_key)
24.{
25. 
26.  // some paramters
27.    $method = "GET";
28.    $host = "ecs.amazonaws.".$region;
29.    $uri = "/onca/xml";
30.     
31.    // additional parameters
32.    $params["Service"] = "AWSECommerceService";
33.    $params["AWSAccessKeyId"] = $public_key;
34.    // GMT timestamp
35.    $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
36.    // API version
37.    $params["Version"] = "2009-03-31";
38.     
39.    // sort the parameters
40.    ksort($params);
41.     
42.    // create the canonicalized query
43.    $canonicalized_query = array();
44.    foreach ($params as $param=>$value)
45.    {
46.        $param = str_replace("%7E", "~", rawurlencode($param));
47.        $value = str_replace("%7E", "~", rawurlencode($value));
48.        $canonicalized_query[] = $param."=".$value;
49.    }
50.    $canonicalized_query = implode("&", $canonicalized_query);
51.     
52.    // create the string to sign
53.    $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
54.     
55.    // calculate HMAC with SHA256 and base64-encoding
56.    $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
57.     
58.    // encode the signature for the request
59.    $signature = str_replace("%7E", "~", rawurlencode($signature));
60.     
61.    // create request
62.    $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
63.     
64.    // do request
65.    $strload = curl_init($request);
66.               curl_setopt($strload, CURLOPT_HEADER, false);
67.               curl_setopt($strload, CURLOPT_RETURNTRANSFER, true);
68.    $response= curl_exec($strload);
69.               curl_close($strload);
70.    if ($response === False)
71.    {
72.        return False;
73.    }
74.    else
75.    {
76.        // parse XML
77.        $pxml = simplexml_load_string($response);
78.        if ($pxml === False)
79.        {
80.            return False; // no xml
81.        }
82.        else
83.        {
84.            return $pxml;
85.        }
86.    }
87.}
88. 
89.     
90.     
91.    //$parsed_xml= aws_signed_request("$amazon_c", array("Operation"=>"ItemLookup","ItemId"=>"$asin","ResponseGroup"=>"Large","AssociateTag"=>"$tag"), $public_key, $private_key);
92.        $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);




Tag : PHP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-12-02 12:49:19 By : jackcools View : 4772 Reply : 7
 

 

No. 1



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้เป็น code aws_signed_request.php
Code (PHP)
01.<?php
02. 
03.//20090627/This is a modified version, see the
04.//return statement some lines before the end of the last function.
05. 
06.function aws_signed_request($region, $params, $public_key, $private_key)
07.{
08./*
09.    Parameters:
10.        $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)
11.        $params - an array of parameters, eg. array("Operation"=>"ItemLookup",
12.                        "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")
13.        $public_key - your "Access Key ID"
14.        $private_key - your "Secret Access Key"
15.    */
16. 
17.    // some paramters
18.    $method = "GET";
19.    $host = "ecs.amazonaws.".$region;
20.    $uri = "/onca/xml";
21. 
22.    // additional parameters
23.    $params["Service"] = "AWSECommerceService";
24.    $params["AWSAccessKeyId"] = $public_key;
25.    // GMT timestamp
26.    $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
27.    // API version
28.    $params["Version"] = "2009-03-31";
29. 
30.    // sort the parameters
31.    ksort($params);
32. 
33.    // create the canonicalized query
34.    $canonicalized_query = array();
35.    foreach ($params as $param=>$value)
36.    {
37.        $param = str_replace("%7E", "~", rawurlencode($param));
38.        $value = str_replace("%7E", "~", rawurlencode($value));
39.        $canonicalized_query[] = $param."=".$value;
40.    }
41.    $canonicalized_query = implode("&", $canonicalized_query);
42. 
43.    // create the string to sign
44.    $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
45. 
46.    // calculate HMAC with SHA256 and base64-encoding
47.    $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
48. 
49.    // encode the signature for the request
50.    $signature = str_replace("%7E", "~", rawurlencode($signature));
51. 
52.    // create request
53.    $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
54. 
55.//20090627 and 20090804/Jaap van Ganswijk: I added the next lines
56.//and commented out the others to prevent getting the file and
57.//interpreting the XML because my script likes to do that itself.
58. 
59.    return $request;
60. 
61.//  // do request
62.//  $response = @file_get_contents($request);
63.//
64.//  if ($response === False)
65.//  {
66.//      return False;
67.//  }
68.//  else
69.//  {
70.//      // parse XML
71.//      $pxml = simplexml_load_string($response);
72.//      if ($pxml === False)
73.//      {
74.//          return False; // no xml
75.//      }
76.//      else
77.//      {
78.//          return $pxml;
79.//      }
80.//  }
81.}
82.?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-02 12:53:11 By : jackcools
 

 

No. 2

Guest


ชื่อ function มันซ้ำกันหรือเปล่าครับ ลองเปลี่ยนชื่อ function ดู
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-02 13:40:16 By : - -
 

 

No. 3



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์


ผมลองเปลี่ยนดูแล้วครับ แต่ก็ไม่ได้เหมือนเดิมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-02 16:59:06 By : jackcools
 

 

No. 4



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ถ้าใช้ include ให้ใช้ require_once("") แทนครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-02 17:15:54 By : webmaster
 

 

No. 5



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 4 เขียนโดย : webmaster เมื่อวันที่ 2010-12-02 17:15:54
รายละเอียดของการตอบ ::
ไม่ได้ครับ เหมือนเดิม ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-03 17:42:57 By : jackcools
 

 

No. 6



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้เป็น code ไฟล์ amazonv4.php บางส่วนครับ ที่ include aws_signed_request.php
Code (PHP)
001.<?php
002.//amazonv4.php
003.//stand-alone PHP example script to use the Amazon Web Services interface
004.//20020816/JvG, released under the GNU GPL
005.//20030203/JvG, adapted for the heavy version
006.//20030630/JvG, adapted further
007.//20030717/JvG, expanded further, this will be released as amazonh3.php
008.//20030912/JvG, fixed the 'register global' issue that a lot of people had trouble with
009.//20030912/JvG, found an excessive ' that caused trouble remembering the product category
010.//20030912/JvG, turned $pagefr0 back into $page (so base 1 instead of base 0, makes script clearer)
011.//20030912/JvG, tried to explain the associate ID issue better
012.//20030912/JvG, in case of the UK locale I show the USA product categories, which looks slightly better
013.//20030912/JvG, in data.php I have disabled Japan, because the script can't really support it
014.//20030912/JvG, in language.php I fixed a spelling mistake in 'buecher USA'
015.//20031125/JvG, commented out the hidden language and locale fields in the form
016.//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
017.//20040202/Tatiana Vygurska found some errors:
018.//20040202/JvG, turned $pagefr0 back to $page in the link to the previous page
019.//20040202/JvG, declared $locale global in function printProduct()!
020.//20040408/JvG, removed the v=2.1 parameter
021.//20040715/JvG, added some suggestions by Wim Roffel
022.//20041207/JvG, utf8_decode() is now executed before interpreting the XML as someone suggested
023.//20041219/JvG, added a couple of lines of code to print the time used to get data from Amazon and handling it
024.//20050118/JvG, tried if the script would also easily work with version 4
025.//20090623/JvG, busy adding the signing that Amazon requires from 20090815
026.//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
027.//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
028.//20090812/JvG, added the comments for 20090804 and 20090812 and tested the caching and I am going to try to put the script online
029.//20090816/JvG, always use signed request, started adding better time measurement
030. 
031.//Thanks for all the questions, improvement tips and help!
032.//Feel free to send more feedback to me at ganswijk@xs4all.nl!
033.//Please mention Amazon in the subject line to avoid my spamfilters
034. 
035.$microtime_init0=$microtime0=getmicrotime();  //time at start and before initializing
036. 
037.$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
038. 
039.//set these to correspond with your site
040.//the user can overrule them
041.$Adefault=array(
042.  'language'           =>'en',           //what language to render the page in
043.  'locale'             =>'us',           //which server's products? available: ca,de,fr,jp,uk,us
044.//'mode'               =>'books',        //what product category?
045.  'page'               =>1,              //first page to show (we are using base-1 not base-0)
046.//'search'             =>'Machiavelli',  //what to search for?
047.  'operation'          =>'ItemSearch',   //what to do?
048.  'searchindex'        =>$cat,        //what product category for search?
049.  'searchparameter'    =>'Keywords',       //what kind of search?
050.  'searchparameterdata'=>$keywords,//$_GET['q']  //what to search for?
051.  //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
052.  'show_array'         =>false,          //debug: show complete incoming array? You can use this to see what other information Amazon is sending
053.  'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
054.  'show_xml'           =>false,          //debug: show incoming XML code from Amazon?
055.);
056.//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
057. 
058.include "data.php";                //static data about Amazon (servers, search fields) v3-
059.include "data_v4.php";             //static data about Amazon (servers, search fields) v4+
060.include "language.php";            //translate the output to the prefered language of the user
061.include "xml.php";                 //interpret XML-data
062.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
063. 
064.//20090624: the following isn't relevant anymore it seems:
065.//$Aassociates_id=array(
066.//  'de'=>'chipdir00' ,  // <-- replace with your amazon.de    associate ID, or leave it as it is
067.//  'fr'=>'chipdir010',  // <-- replace with your amazon.fr    associate ID, or leave it as it is
068.//  'jp'=>'INVALID'   ,  // <-- replace with your amazon.co.jp associate ID, or leave it as it is
069.//  'uk'=>'chipdir03' ,  // <-- replace with your amazon.co.uk associate ID, or leave it as it is
070.//  'us'=>'chipdir'   ,  // <-- replace with your amazon.com   associate ID
071.//);
072. 
073. 
074.//20090623: The signed request version requires these two parameters:
075.//$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
076.//$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
077.$public_key =$AWSAccessKeyId ;
078.$private_key=$SecretAccessKey;
079. 
080.//other flags:
081.//this doesn't seem to be relevant anymore:
082.//$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.
083.                      //change it to false when you prefer to get only 5% ;-)
084.                      //see http://forums.prospero.com/n/mb/message.asp?webtag=am-assosdev&;msg=6.1&ctx=0, or search the forum for 'nosim'
085.                      //This is only helpful for certain books
086.                      //correction: keep this option set to true, to prevent the showing of Amazon's annoying distraction pages.
087.                      //20080530: i don't know if this is still relevant for version 4
088.$f_user_search=true;  //add a user search form and allow user searches?
089. 
090.//=============================================================================
091.//==You don't have to change anything below this line to start earning money.==
092.//=============================================================================
093. 
094.if ($jaap) {
095.  print_array($_GET);
096.}
097. 
098.//what are the user's prefered languages?
099.$Ahttp_lang=split(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
100. 
101.if ($jaap) {
102.  print_array($Ahttp_lang);
103.}
104. 
105.//try to find the visitor's prefered language, this is still experimental
106.foreach ($Ahttp_lang as $i=>$d) {
107.  if ($Axl[$l=substr($d,0,2)]) {
108.    $pref_lang=$l;
109.    break;
110.  }
111.}
112. 
113.$Adefault['language']=$pref_lang;
114. 
115.if ($jaap) {
116.  echo "prefered available language='$pref_lang'<br />\n";
117.  print_array($Ahttp_lang);
118.}
119. 
120.//for all parameters see if the user has overruled it or use the default
121.foreach ($Adefault as $i=>$d) {
122.  $$i=$_GET[$i]?$_GET[$i]:$d;
123.  if ($jaap) echo "$i = '".$$i."'<br />\n";
124.}
125. 
126.//use which servers?
127.$norserver=$Aserver[$locale]['nor'];
128.$xmlserver=$Aserver[$locale]['xml'];
129. 
130.//20090817: this is no longer used it seems:
131.//$dev_token='D2WMCOIPS9D14E';
132.//you can replace this with your own developer token after you have changed the script a lot
134.//see:
136. 
137.//form the URL to send to Amazon as a search request
138.//this is the part that is search specific
139.$parameters=array(
140.  'Operation'       =>'ItemSearch'            ,
141.  'Keywords'        =>urlencode($search)      ,
142.  'SearchIndex'     =>$searchindex            //Books for example.
143.    "BrowseNode"   =>$node   ,
144.  "$searchparameter"=>$searchparameterdata    ,
145.  'ItemPage'        =>$page                   //which page?
146.//'Service'         =>'AWSECommerceService'   ,  //this makes it version 4
147.//'SubscriptionId'  =>$subscriptionid         ,  //is this correct?
148.//'AWSAccessKeyId'  =>$awsaccesskeyid         ,  //is this correct?
149.'AssociateTag'    =>$amazonid ,
150.  'ResponseGroup'   =>'Medium,Reviews'                //Small, Medium or Large
151.);
152.$ext=$Aserver[$locale]['ext'];  //extension of server, see data.php
153.$file_data=$ext;
154.ksort($parameters);
155.foreach ($parameters as $i=>$d) {
156.  $file_data.='&'.$i.'='.$d;
157.}
158.$file=aws_signed_request($ext,$parameters,$public_key,$private_key);

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-03 17:49:08 By : jackcools
 

 

No. 7

Guest


ไม่รู้ว่าแก้ได้หรือยัง
ปัญหานี้คือมีการเรียกไฟล์ที่ประกาศฟังก์ชั่นซ้ำซ้อนเลยทำให้เกิด error

วิธีแก้คงต้องไล่สเต็ปละครับว่าไฟล์ไหนที่เป้นปัญหา

หรือถ้าจะแก้แบบลวก ๆ อาจจะใช้

if(!function_exists("aws_signed_request")) {
function aws_signed_request($region, $params, $public_key, $private_key){
ฟังก์ชั่น aws_signed_request ทั้งหมด..............
}
}

ไม่แน่ใจว่าจะ "เอาอยู่" หรือเปล่า




พอดีผมเจออีกปัญหา เจอเป็นบางครั้งเลยค้น google มาเจอกระทู้นี้

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : expected '>' in aws_signed_request.php

ไม่แน่ใจว่า amz มีการเปลี่ยนแปลงโครงสร้าง xml ที่ return กลับมาหรือยังไง
แต่บางครั้งก็ผ่าน บางครั้งก็ติด

ใครเจอปัญหานี้ช่วยแนะนำที

ขอบคุณอย่างสูงยิ่ง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-15 00:35:22 By : เด็กปัญญาอ่อน
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยครับ ผมมีเรื่องปัญหา Cannot redeclare aws_signed_request() แก้ไม่ได้ครับ ช่วยหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่