Hi Community,
I have wrote a simple api-login-script but every time I get the error message: badlogin.
I have tested the login with some accounts and i'm sure that the username and password are correct.
You can very simple the script, if you have a vbulletin installation and a activated api function.
All what you need is to edit the variable $apiurl and $apikey and uplodad the script to your webspace.
I would be very appreciated if someone can help me. :-)
PHP Code:
<?php
//Parameters
$clientname = "mysuperclient";
$clientversion ="0.1";
$platformname = "example";
$platformversion ="2.5";
$uniqueid = "1234";
$apiurl='http://www.my-domain.de/forum/api.php'; // Edit here
$apikey = 'myAPIKey'; // Edit here
error_reporting(E_ALL);
///////////////////////////////////////// ACTION
if(isset($_POST['username']) && isset($_POST['password'])) {
$userName = $_POST['username'];
$password = $_POST['password'];
if($userName != '' && $password != '') {
$jsarray = initApiRequest($clientname, $clientversion, $platformname, $platformversion, $uniqueid, $apiurl);
$jsarray = doLogIn($jsarray, $userName, $password, $apikey, $apiurl);
} else {
echo "userName == '' || password == ''";
}
}
///////////////////////////////////////// FUNCTIONS
function initApiRequest($clientname, $clientversion, $platformname, $platformversion, $uniqueid, $apiurl) {
$init_request = $apiurl .'?api_m=api_init&clientname='. $clientname .'&clientversion='.$clientversion .'&platformname='.$platformname .'&platformversion=' .$platformversion .'&uniqueid='.$uniqueid;
$jsarray = doRestRequest($init_request);
return $jsarray;
}
function doLogIn($jsarray, $userName, $password, $apikey, $apiurl) {
$requestparams = array('api_m' => 'login_login', 'vb_login_username' => $userName, 'vb_login_md5password' => md5($password));
ksort($requestparams);
$login_string = http_build_query($requestparams, '', '&');
$apiaccesstoken = $jsarray->{'apiaccesstoken'};
$apiclientid = $jsarray->{'apiclientid'};
$secret = $jsarray->{'secret'};
$apiversion = $jsarray->{'apiversion'};
$api_sig = md5($login_string . $apiaccesstoken . $apiclientid . $secret . $apikey);
$api_registration_information = 'api_c='. $apiclientid .'&api_s='. $apiaccesstoken .'&api_sig='. $api_sig .'&api_v='. $apiversion;
$login_request = $apiurl .'?'. $api_registration_information .'&'. $login_string;
$jsarray = doRestRequest($login_request);
return $jsarray;
}
function doRestRequest($restRequest) {
echo "<br>DO REST REQUEST[". $restRequest ."]<br>";
$content = '';
//Open and read the content
$fp = fopen($restRequest, 'r');
// keep reading until there's nothing left
while ($line = fread($fp, 1024)) {
$content .= $line;
}
fclose($fp);
echo "<hr>";
var_dump(json_decode($content, true));
echo "<hr>";
//decode the content
$jsarray = json_decode($content);
return $jsarray;
}
?>
<html>
<head>
</head>
<body>
<form action="myresttest.php" method="post">
<p>Username: <input type="text" name="username" /></p>
<p>Password: <input type="password" name="password" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>