Размер файла: 3.96Kb
<?
//Autor: HoldFast
//http://vk.com/holdfast
//Распространяйте как хотите, мне пох
session_start();
$session = $_GET['sess'];
$sig = $_GET['sig'];
$answer = $_GET['a'];
$step = $_GET['s'];
$excl = $_GET['excl'];
function new_session()
{
$data = json_decode(file_get_contents("http://api-ru1.akinator.com/ws/new_session?partner=1"));
$_SESSION['step'] = null;
$arr['session'] = $data->parameters->identification->session;
$arr['sig'] = $data->parameters->identification->signature;
$arr['question'] = $data->parameters->step_information->question;
$arr['step'] = $data->parameters->step_information->step;
return $arr;
}
function exclusion($session, $sig, $step)
{
$data = json_decode(file_get_contents("http://api-ru1.akinator.com/ws/exclusion?session=$session&signature=$sig&step=$step&forward_answer=1"));
$arr['session'] = $session;
$arr['sig'] = $sig;
$arr['question'] = $data->parameters->question;
$arr['step'] = $data->parameters->step;
$arr['progress'] = round(intval($data->parameters->progression));
return $arr;
}
function lists($session, $sig, $step)
{
$data = json_decode(file_get_contents("http://api-ru1.akinator.com/ws/list?session=$session&signature=$sig&step=$step&size=2&max_pic_width=246&max_pic_height=299&pref_photos=OK-FR&mode_question=0"));
echo '<img src="http://api-ru1.akinator.com/photo0/' . $data->parameters->elements[0]->element->picture_path . '"><br>';
echo $data->parameters->elements[0]->element->name . "<br>";
echo $data->parameters->elements[0]->element->description . "<br>";
echo '<a href="?excl=1&sess=' . $session . '&sig=' . $sig . '&s=' . $step . '&a=1">Нет, это не этот персонаж</a><br>';
}
function answer($session, $sig, $answer, $step)
{
$data = json_decode(file_get_contents("http://api-ru1.akinator.com/ws/answer?session=$session&signature=$sig&step=$step&answer=$answer"));
$arr['session'] = $session;
$arr['sig'] = $sig;
$arr['question'] = $data->parameters->question;
$arr['step'] = $data->parameters->step;
$arr['progress'] = round(intval($data->parameters->progression));
return $arr;
}
if (empty($session) || empty($sig))
$arr = new_session();
else {
if ($excl != 1)
$arr = answer($session, $sig, $answer, $step);
else
$arr = exclusion($session, $sig, $step);
if (empty($arr['question']))
$arr = new_session();
}
if (empty($_SESSION['step']))
$_SESSION['step'] = 25;
if ($_SESSION['step'] <= 25 && $excl == 1) {
$_SESSION['step'] = 50;
}
echo '<html>
<head>
<title>Akinator</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>';
if ($arr['step'] < $_SESSION['step'] && $arr['progress'] < 99) {
echo '<table><tr><td id="left">';
echo '<span class="number">Вопрос №' . ($arr['step'] + 1) .":</span>";
echo '<br><span class="question">' . $arr['question'] . '</span><br><div class="answer">';
echo '<a href="?sess=' . $arr['session'] . '&sig=' . $arr['sig'] . '&s=' . $arr['step'] . '&a=0">Да</a><br>';
echo '<a href="?sess=' . $arr['session'] . '&sig=' . $arr['sig'] . '&s=' . $arr['step'] . '&a=1">Нет</a><br>';
echo '<a href="?sess=' . $arr['session'] . '&sig=' . $arr['sig'] . '&s=' . $arr['step'] . '&a=2">Не знаю</a><br>';
echo '<a href="?sess=' . $arr['session'] . '&sig=' . $arr['sig'] . '&s=' . $arr['step'] . '&a=3">Возможно, частично</a><br>';
echo '<a href="?sess=' . $arr['session'] . '&sig=' . $arr['sig'] . '&s=' . $arr['step'] . '&a=4">Скорее нет, не совсем</a><br>';
echo '</div></td><td><img src="akinator.png"></td></tr><table>';
} else
lists($arr['session'], $arr['sig'], $arr['step']);
echo '<hr><a href="?">Начать сначала</a></body>
</html>';
?>