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,027

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



 

ช่วยหน่อยครับ ผมมีเรื่องปัญหา 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)
<?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);






Tag : PHP







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

 

No. 1



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



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


อันนี้เป็น code aws_signed_request.php
Code (PHP)
<?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 ดู
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-12-02 13:40:16 By : - -
 

 

No. 3



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



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


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


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 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)
<?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); 

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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