<?php
error_reporting(E_ERROR);
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
session_start();
if ($_POST) {
  // check if its an ajax request, exit if not, ie. hacker injection
  if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
    $output = json_encode(array(
      'type'=>'error', 
      'text' => 'There was an error, the request must be an Ajax POST.'
    ));
    exit($output);
  }
  $shapeid = $_POST["shapeid"];
  //echo "ShapeID: ".$shapeid."\r\n";
  $shapetarget = $_SESSION['shapetarget'];
  //echo "ShapeTarget: ".$shapetarget."\r\n";
  function returnSuccess() {
    $data=array();
    $data['success'] = 'match';
    header('Content-Type: application/json');
    echo json_encode($data);
    exit;
  }
  function returnFail() {
    $data=array();
    $data['success'] = 'fail';
    header('Content-Type: application/json');
    echo json_encode($data);
    exit;
  }
  if ($shapetarget == $shapeid)
    returnSuccess();
  returnFail();
}
?>