Last active
August 29, 2015 13:59
-
-
Save bradenbest/10666917 to your computer and use it in GitHub Desktop.
In this example, I try to explain the Newgrounds API
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 | |
$sql_username = "root"; | |
$sql_password = "TOMFULPRULEZ1"; | |
// For NG's sake, I hope this isn't actually their root sql password. It would be hilarious, though | |
$database = "Newgrounds Gateway"; | |
$db = mysqli_connect($sql_username, $sql_password, $database); | |
?> |
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 | |
include('connect.php'); | |
session_start(); | |
// Note: this is pseudo-code since I don't have a reference handy right now. Don't actually try to use it | |
// I mean that the functions used here are likely to be fictionally named alternatives to the real function | |
// for example, exist() is not used to check $_POST's existence, it might not even be an existing function | |
if(exist($_POST)){ | |
if($_POST['type'] == 'api_connect'){ | |
$apiid = $_POST['api_id']; | |
$enckey = $_POST['enc_key']; | |
$result = $db->query("SELECT * FROM api WHERE apiid='$apiid' AND enckey='$enckey'"); | |
if($result){ | |
$arr = $db->fetch_array($result); | |
$_SESSION['user_api_id'] = $arr['u_api_id']; | |
} | |
} else if($_POST['type'] == 'api_medal_unlock'){ | |
if($_SESSION['user_api_id']){ // if this exists, then there has been a successful connection | |
$mname = $_POST['medal_name']; | |
$u_api_id = $_SESSION['user_api_id']; | |
$result = $db->query("SELECT * FROM medals WHERE medal_name='$mname' AND u_api_id='$u_api_id'"); | |
if($result){ // medal that is owned by user exists | |
$db->query("UPDATE medals SET(unlocked='1') WHERE medal_name='$mname' AND u_api_id='$u_api_id'"); | |
}else{ | |
die("Error: no medal with that name exists"); | |
} | |
}else{ | |
die("Error: not connected to API"); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment