Generating a Token for customer using httpapi.com api. It requires GET HTTP Method. You need auth-userid, api-key or auth-password, username, passwd and ip parameters for that. You can authenticates a customer by returning an authentication token on successful authentication. In case of any errors, a status key with value as ERROR alongwith an error message will be returned. For this you can use following function. We hope you like that code.
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ function GENERATE_TOKEN($username,$passwd) { # 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($username) && isset($passwd)) { $client_ip = $_SERVER['REMOTE_ADDR']; $generate_token = $api_url.'/api/customers/generate-token.json?auth-userid='.$auth_userid.'&api-key='.$api_key.'&username='.urlencode($username).'&passwd='.urlencode($passwd).'&ip='.$client_ip; $result = @file_get_contents($generate_token); $token = json_decode($result, true); return $token; } return false; } ?>
Function USAGE
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/
$_token = GENERATE_TOKEN("send_username","send_passwd");
if($_token)
{
// token successful authentication
// after generating a token you need to Authenticating a Token this will be our next post
}
else
{
echo "Invalid Username or Password.";
}
?>
0 comments:
Post a Comment