Thursday, March 13, 2014

how to register customer httpapi curl php

3/13/2014

Signing Up a Customer Account using the httpapi.com api. It requires POST HTTP Method. You can use following function to register customer account with api intergration. You need auth-userid and api-key or auth-password for that. Look at follow code for more information.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




function SIGNUP_CUSTOMER($data)
{
 // post all required data through via $_POST in $data
 $_data = $data;

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 

 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

 if(isset($auth_userid) && isset($api_key))
 {
  $handle = curl_init();
  curl_setopt($handle, CURLOPT_URL,$api_url.'/api/customers/signup.xml');
  curl_setopt($handle, CURLOPT_POST, 1);
  curl_setopt($handle, CURLOPT_POSTFIELDS,
              'auth-userid='.$auth_userid.'&api-key='.$api_key.'&username='.urlencode($_data['username']).'&passwd='.urlencode($_data['passwd']).'&name='.urlencode($_data['name']).'&company='.urlencode($_data['company']).'&address-line-1='.urlencode($_data['address-line-1']).'&city='.urlencode($_data['city']).'&state='.urlencode($_data['state']).'&country='.urlencode($_data['country']).'&zipcode='.urlencode($_data['zipcode']).'&phone-cc='.urlencode($_data['phone-cc']).'&phone='.urlencode($_data['phone']).'&lang-pref=en');



  // receive server response ...
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  $server_output = curl_exec ($handle);
  curl_close ($handle);


  // echo $server_output;
  if( strpos($server_output,'ERROR') === FALSE)
  {
   echo "You're Almost Done. Your sign up  process is completed.";
   return true;
  }
  else
  {
   echo "".$server_output."";
  }

 }

 return false;


}

?>

Function USAGE
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




 
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {

       SIGNUP_CUSTOMER($_POST);
                              
    }
    else
    {
        $_POST = NULL;
    }

?>


helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top