Skip to content

Instantly share code, notes, and snippets.

@AlexanderNorway
Last active October 8, 2015 11:58
Show Gist options
  • Save AlexanderNorway/3329121 to your computer and use it in GitHub Desktop.
Save AlexanderNorway/3329121 to your computer and use it in GitHub Desktop.
<?php
define('VERIFY_TOKEN', 'yourappssecret');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == VERIFY_TOKEN) {
echo $_GET['hub_challenge'];
} else if ($method == 'POST') {
if ( isset( $_SERVER['HTTP_X_HUB_SIGNATURE'] ) ) {
$post_body = file_get_contents("php://input");
if ($_SERVER['HTTP_X_HUB_SIGNATURE'] == "sha1=" . hash_hmac('sha1', $post_body, VERIFY_TOKEN)) {
//Connect To Database
$hostname='Your host address';
$username='Your username';
$password='Your password';
$dbname='Your database name';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die(mysql_error());
$object = json_decode($post_body, true);
foreach($object->entry as $update)
{
// For each entry in notification, insert a row of information into the table "FaceBook"
$changed_fields = $update->changed_fields[0];
$result = mysql_query("INSERT INTO FaceBook (uid, id, time, changed_fields) VALUES('$update->uid', '$update->id', '$update->time', '$changed_fields')")
or die(mysql_error());
}
mysql_close();
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment