Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Setting values for the database
- $servername = "";
- $username = "";
- $password = "";
- $dbname = "";
- //Connecting the database
- $conn = mysqli_connect($servername, $username, $password,$dbname);
- $email = $_POST['email'];
- $msg = $_POST['msg'];
- $noti =$_POST['noti'];
- echo "Submitted";
- //Retrievin Registration ID from the database with the help of email
- $sql = "SELECT regid FROM gcm where email='"'.$email.'"'";
- //Executing the query
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- $regid = mysqli_fetch_assoc($result);
- } else {
- echo "0 results";
- }
- //closing the database connection
- mysqli_close($conn);
- //Setting Server API Key that we generated in the Google Developer Console
- define( 'API_ACCESS_KEY', 'ENTER YOUR OWN API KEY' );
- //Storing Fetched Registration ID to the vaiable 'to'. 'to' is an array of registration IDs whom we want to send push notification
- $to=$regid;
- //This 'to' is assigned to registrationIds
- $registrationIds = array($to);
- //Message Array
- $msg = array
- (
- //Message that we want to send in the push notification
- 'message' => $msg,
- //Title that we want to set for the push notification
- 'title' => $noti,
- //Subtitle, ticker text
- 'subtitle' => 'This is a subtitle. subtitle',
- 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
- //Sets to true or '1' if we want device to vibrate and make sound when user recieves push notification
- 'vibrate' => 1,
- 'sound' => 1,
- 'largeIcon' => 'large_icon',
- 'smallIcon' => 'small_icon'
- );
- //RegistrationIds and message are assigned to fields
- $fields = array
- (
- 'registration_ids' => $registrationIds,
- 'data' => $msg
- );
- $headers = array
- (
- //Setting headers for API acceess key and content type
- 'Authorization: key=' . API_ACCESS_KEY,
- 'Content-Type: application/json'
- );
- //Initializing Curl
- $ch = curl_init();
- //Posting data to the following URL
- curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
- //Post Data = True, Defining Headers and SSL Verifier = false
- curl_setopt( $ch,CURLOPT_POST, true );
- curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
- //Posting fields array in json format
- curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
- //Executing Curl
- $result = curl_exec($ch );
- //Closing Curl
- curl_close( $ch );
- echo $result;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="format-detection" content="telephone=no">
- <meta name="msapplication-tap-highlight" content="no">
- <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
- <title>Send Me </title>
- <!--Stylesheet Files : jQuery Mobile CSS File, Customized CSS File-->
- <link rel="stylesheet" href="css/jquery.mobile-1.4.5.css">
- <link rel="stylesheet" href="css/my.css">
- <!--AJAX Library, jQuery File : Library,and Mobile Library -->
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
- <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
- <script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>
- </head>
- <!--Beginning of the Body-->
- <body>
- <div data-role="page">
- <div data-role="header" data-position="fixed" class="ui-header ui-bar-a ui-header-fixed slidedown" role="banner">
- <h1>Send Me</h1>
- </div>
- <div data-role="main" class="ui-content" id="main">
- <!--Form containing fields registered email, message user wants to send, title of the push notification and submit button-->
- <form action="http://juth.esy.es/sendnotification.php" method="post">
- <ul data-role="listview" data-inset="true">
- <li class="ui-field-contain">
- <label for="name2">Enter Your Registered Email:</label>
- <input type="text" name="email" id="email" value="" data-clear-btn="true">
- </li>
- <li class="ui-field-contain">
- <label for="name2">Enter Your Message:</label>
- <input type="text" name="msg" id="message" value="" data-clear-btn="true">
- </li>
- <li class="ui-field-contain">
- <label for="name2">Enter Notification Title:</label>
- <input type="text" name="noti" id="notification" value="" data-clear-btn="true">
- </li>
- <li class="ui-body ui-body-b">
- <center><input type="submit" id="submit" value="Send Notification" class="ui-shadow ui-btn ui-corner-all"/></center>
- </li>
- </ul>
- </form>
- <!--End of the form-->
- /div>
- </div>
- </body>
- <!--End of the body-->
- </html>
Add Comment
Please, Sign In to add comment