Skip to content

Instantly share code, notes, and snippets.

@hungdh0x5e
Created January 15, 2016 08:49
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 hungdh0x5e/77c3836a45b76f9e58fa to your computer and use it in GitHub Desktop.
Save hungdh0x5e/77c3836a45b76f9e58fa to your computer and use it in GitHub Desktop.
GCM with Android tutorial
<?php
/**
* Registering a user device
* Store reg id in users table
*/
$body = file_get_contents('php://input');
$postvars = json_decode($body, true);
if (isset($postvars["name"]) && isset($postvars["email"]) && isset($postvars["regId"])) {
$name = $postvars["name"];
$email = $postvars["email"];
$gcm_regid = $postvars["regId"]; // GCM Registration ID
// Store user details in db
include_once './db_functions.php';
include_once './GCM.php';
$db = new DB_Functions();
// $gcm = new GCM();
if($db->isTokenExisted($gcm_regid)){
$response["status"] = "false";
$response["error"] = "Registration token is existed!";
echo json_encode($response);
}else{
$res = $db->storeUser($name, $email, $gcm_regid);
if($res){
$response["status"] = "ok";
$response["message"] = "Register success!";
echo json_encode($response);
}else{
$response["status"] = "false";
$response["error"] = "Registration token is existed!";
echo json_encode($response);
}
}
} else {
$response["status"] = "false";
$response["error"] = "Param include: name, email, token";
echo json_encode($response);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment