Last active
October 10, 2018 16:41
-
-
Save erfg12/3575f59f5a64e209b9851ee482160a6e to your computer and use it in GitHub Desktop.
IGDB.com PHP API search for game ID by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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