Skip to content

Instantly share code, notes, and snippets.

@erfg12
Last active October 10, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erfg12/3575f59f5a64e209b9851ee482160a6e to your computer and use it in GitHub Desktop.
Save erfg12/3575f59f5a64e209b9851ee482160a6e to your computer and use it in GitHub Desktop.
IGDB.com PHP API search for game ID by name
<?PHP
$key = 'IGDB_API_KEY_HERE'; //your IGDB api key goes here
if (isset($_POST['game'])) {
header('Content-Type: application/json; charset=utf-8');
$json_url = 'https://api-endpoint.igdb.com/games/?search='.urlencode($_POST['game']).'&fields=name';
$ch = curl_init( $json_url );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('user-key:'.$key, 'Accept: application/json')
);
curl_setopt_array( $ch, $options );
$json = preg_replace('/[ ]{2,}|[\t\n\r\(\)\;]/', '', trim(curl_exec($ch)));
$data = json_decode($json);
print_r($data);
} else {
?>
<form method="post" action="igdb_search.php">
<input type="text" name="game" placeholder="game name">
<input type="submit" value="search">
</form>
<?PHP } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment