...
You need to enter your secret code that will be used to create access hash in your application code.
Code sample: Login customer
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
// Get cURL resource
$ch = curl_init();
// Set AutoLogin url
curl_setopt($ch, CURLOPT_URL, 'http://yourhostbillurl.com/index.php?cmd=autologin&action=login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Data to post:
$email= "user@email.com"; //Client's email address
$duration = "160"; //Time in seconds for how long user login link will work
$secret = "SECRET_CODE"; //Secret code set in module configuration (in previous step)
$hash = md5($email.$secret.$duration); //Verification string
$body = http_build_query([
'email'=>$email,
'duration'=>$duration,
'hash'=>$hash,
'redirect' => 'http://yourhostbillurl.com/index.php?cmd=clientarea&action=invoices', //optional
]); //data to post
// Set POST data
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// Send the request & save response to $resp
$resp = curl_exec($ch);
if(!$resp) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} else {
$array = json_decode($resp,true);
if($array['success']) {
$login_url = $array['login_url']; //url to link customer to HostBill
$token = $array['token']; //token we can use to log user out
} else {
die('Error: "' . $array['error'] .'"');
}
}
curl_close($ch);
|
Code sample: Logout customer
...