Server side code for GCM push notification in PHP
For a complete tutorial on how you can make use of this project visit this link. #PHP files at a glance:
- commonutils.php: Common utilities.
- config.php: Defines constants. Among all the codes, only this file needs to be modified. Other files can be left untouched.
- db_functions.php: Database functions for making database connection, storing/retrieving users and their info and performing various tests on the gcm_users table.
- gcm_main.php: This is the file that is responsible for sending push notification.
- index.php: This is the form i.e the admin panel page.
- register.php: This is the php file that your client app should post registration id to register with your server.
- unregister.php: This is the php file that your client app should post registration id to un-register with your server.
#Notable PHP functions at a glance:
redirect($url): Redirects to the specified url.storeUser($gcm_regid, $instanceId, $name, $email): Member function of DB_Functions_GCM class. Stores registration id in database along with other info.checkUserById($id): Member function of DB_Functions_GCM class. Checks if an existing user already exists in database with the same registration id.deleteUserById($id): Member function of DB_Functions_GCM class. Deletes a user from database according to the registration id (unsubscribe).sendPushNotification($registration_ids, $message): Sends push notification$messageto all ids in the$registration_idsarray.