I try to connect the Api from other hosting to server game but show: Error: Connection failed
Click Back Button to correct.
<?php
$url = "
http://62.75.254.59:8087/api"; // <-- use your game server IP
$pw = "adminx"; // <-- use your api password
function Poker_API($url,$params,$assoc)
{
$curl = curl_init($url);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
curl_setopt($curl,CURLOPT_TIMEOUT,30);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$response = trim(curl_exec($curl));
curl_close($curl);
$api = Array();
if ($assoc) // associative array result
{
if (empty($response))
{
$api["Result"] = "Error";
$api["Error"] = "Connection failed";
}
else
{
$paramlist = Explode("\r\n",$response);
foreach ($paramlist as $param)
{
$namevalue = Explode("=",$param,2);
$api[$namevalue[0]] = $namevalue[1];
}
}
}
else // regular array result
{
if (empty($response))
{
$api[] = "Result=Error";
$api[] = "Error=Connection failed";
}
else
{
$paramlist = Explode("\r\n",$response);
foreach ($paramlist as $param) $api[] = $param;
}
}
return $api;
}
?>
<html>
<body>
<?php
$avatarurl = "
http://62.75.254.59:8087/avatar"; // set your url here
$avatarmax = 64; // number of avatars available
$avatarswf = false; // set to true if custom avatars are in swf format
include "API.php";
if (isset($_REQUEST["Submit"]))
{
$Player = $_REQUEST["Player"];
$RealName = $_REQUEST["RealName"];
$Gender = $_REQUEST["Gender"];
$Location = $_REQUEST["Location"];
$Password1 = $_REQUEST["Password1"];
$Password2 = $_REQUEST["Password2"];
$Email = $_REQUEST["Email"];
$Avatar = $_REQUEST["Avatar"];
if ($Password1 <> $Password2) die("Password mismatch. Click Back Button to correct.");
$params = "Password=$pw&Command=AccountsAdd" .
"&Player=" . urlencode($Player) .
"&RealName=" . urlencode($RealName) .
"&PW=" . urlencode($Password1) .
"&Location=" . urlencode($Location) .
"&Email=" . urlencode($Email) .
"&Avatar=" . urlencode($Avatar) .
"&Gender=" . urlencode($Gender) .
"&Chat=" . "Yes" .
"&Note=" . urlencode("Account created via API");
$api = Poker_API($url,$params,true);
if ($api["Result"] == "Ok") echo "Account successfully created for $Player";
else echo "Error: " . $api["Error"] . "<br>Click Back Button to correct.";
exit;
}
?>
<h3>Create New Account</h3>
<form method="post">
<table>
<tr><td>Your player name:</td><td><input type="text" name="Player" /></td></tr>
<tr><td>Your real name:</td><td><input type="text" name="RealName" /></td></tr>
<tr><td>Your gender:</td><td><input type="radio" name="Gender" Value="Male" checked>Male</input>
<input type="radio" name="Gender" Value="Female">Female</input></td></tr>
<tr><td>Your location:</td><td><input type="text" name="Location" /></td></tr>
<tr><td>Select a password:</td><td><input type="password" name="Password1" /></td></tr>
<tr><td>Confirm password:</td><td><input type="password" name="Password2" /></td></tr>
<tr><td>Your email address:</td><td><input type="text" name="Email" /></td></tr>
<tr><td>Your avatar:</td><td>
<div style="width: 100px; height: 175px; overflow: auto; border: solid 2px">
<?php
for ($i=1; $i<=$avatarmax; $i++)
{
$s = "<input type='radio' name='Avatar' value='$i'";
if ($i == 1) $s .= " checked";
$s .= ">";
if ($avatarswf)
{
$s .= "<object width='48' height='48'>" .
"<param name='movie' value='$avatarurl?Index=$i'>" .
"<embed src='$avatarurl?Index=$i' width='48' height='48' type='application/x-shockwave-flash'>" .
"</embed>" .
"</object>";
}
else $s .= "<img src='$avatarurl?Index=$i' align='middle'>";
echo $s . "<br>\r\n";
}
?>
</div>
</td></tr>
</table>
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>