PHP Getting Started Example

From Wiki.zanox.com

Jump to: navigation, search

Web Services > Getting Started Tutorial > PHP Getting Started Example

[edit] PHP

<?php 
 if(isset($_REQUEST['search']) && $_REQUEST['search'] != '') {
   $search = urlencode($_REQUEST['search']);
 } else {
   $search = urlencode('hello world');
 }
 
 
 $zanox_server = 'http://api.zanox.com';
 $zanox_host = 'api.zanox.com';
 $zanox_Request_Method = 'GET';
 $zanox_application_id = utf8_encode('ZXWS ');
 $zanox_application_id .= utf8_encode('1234567890987654321');//USE YOUR OWN!
 $zanox_shared_key = 'abcdefghijklmnopqrstuvwxyz';//USE YOUR OWN!
 $zanox_get_param_date = gmdate('D, d M Y H:i:s').' GMT'; // Mon, 09 Jun 2008 08:17:35 GMT
 $zanox_Resource_URL = '/products?q='.$search;
 $zanox_string2sign = utf8_encode($zanox_Request_Method.$zanox_Resource_URL.$zanox_get_param_date);
 $zanox_signature = base64_encode(hash_hmac( 'SHA1' , $zanox_string2sign , $zanox_shared_key, true));
 $zanox_application_id_security = $zanox_application_id.':'.$zanox_signature;
 $zanox_Request_URL =      $zanox_server.'/xml'.$zanox_Resource_URL;
 
 $header[] = "Date: " . $zanox_get_param_date;
 $header[] = "Authorization: " . $zanox_application_id_security;
 
 $cobj=curl_init($zanox_Request_URL);
 curl_setopt($cobj, CURLOPT_HTTPHEADER, $header);
 curl_setopt ($cobj, CURLOPT_GET, true); // only with GET-Request, else the opts for post etc.
 curl_setopt($cobj, CURLOPT_RETURNTRANSFER, true);
 $Result=curl_exec($cobj);
 curl_close($cobj);
?>

[edit] HTML

<html>
  <head>
    <title>Product search: zanox webservices example</title>
  </head>
  <body>
    <form action="#" method="get">    
      <input type="text" name="search" value="Searchstring" />
      <input type="submit" value="Search Products" />
    </form>
    <textarea style="width: 100%;height: 10%;"><?php echo $Result ?></textarea>
  </body>
</html>
Personal tools