Looping FCM token in CURL script from MySQL database
up vote
0
down vote
favorite
I have a curl script that connects to Firebase in order to send push notificaitions but the problem is that the notification is sent to only one registration token, when it is supposed to send to multiple registration tokens (devices)
below is the CURL code
<?php
require "init.php";
$body=$_POST['message'];
$title=$_POST['title'];
$url=$_POST['url'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
$key=$row[1];
$headers=array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
$fields = array(
'to' =>$key,
'data' => $message,
'priority'=>'high'
);
$payload=json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result=curl_exec($curl_session);
mysqli_close($con);
?>
php mysql firebase curl firebase-cloud-messaging
add a comment |
up vote
0
down vote
favorite
I have a curl script that connects to Firebase in order to send push notificaitions but the problem is that the notification is sent to only one registration token, when it is supposed to send to multiple registration tokens (devices)
below is the CURL code
<?php
require "init.php";
$body=$_POST['message'];
$title=$_POST['title'];
$url=$_POST['url'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
$key=$row[1];
$headers=array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
$fields = array(
'to' =>$key,
'data' => $message,
'priority'=>'high'
);
$payload=json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result=curl_exec($curl_session);
mysqli_close($con);
?>
php mysql firebase curl firebase-cloud-messaging
1
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
please update your code
– Joseph_J
Nov 11 at 1:37
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a curl script that connects to Firebase in order to send push notificaitions but the problem is that the notification is sent to only one registration token, when it is supposed to send to multiple registration tokens (devices)
below is the CURL code
<?php
require "init.php";
$body=$_POST['message'];
$title=$_POST['title'];
$url=$_POST['url'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
$key=$row[1];
$headers=array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
$fields = array(
'to' =>$key,
'data' => $message,
'priority'=>'high'
);
$payload=json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result=curl_exec($curl_session);
mysqli_close($con);
?>
php mysql firebase curl firebase-cloud-messaging
I have a curl script that connects to Firebase in order to send push notificaitions but the problem is that the notification is sent to only one registration token, when it is supposed to send to multiple registration tokens (devices)
below is the CURL code
<?php
require "init.php";
$body=$_POST['message'];
$title=$_POST['title'];
$url=$_POST['url'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
$key=$row[1];
$headers=array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
$fields = array(
'to' =>$key,
'data' => $message,
'priority'=>'high'
);
$payload=json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result=curl_exec($curl_session);
mysqli_close($con);
?>
php mysql firebase curl firebase-cloud-messaging
php mysql firebase curl firebase-cloud-messaging
edited Nov 11 at 1:15
Frank van Puffelen
225k26366393
225k26366393
asked Nov 11 at 0:17
Neliswa Astute
365
365
1
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
please update your code
– Joseph_J
Nov 11 at 1:37
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04
add a comment |
1
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
please update your code
– Joseph_J
Nov 11 at 1:37
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04
1
1
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
please update your code
– Joseph_J
Nov 11 at 1:37
please update your code
– Joseph_J
Nov 11 at 1:37
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
One thing that I noticed was you were storing your curl result into the variable $result
. That is the same variable that your query results are in, thus replacing it's value. That will cause problems.
Give this a try.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result))
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244702%2flooping-fcm-token-in-curl-script-from-mysql-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
One thing that I noticed was you were storing your curl result into the variable $result
. That is the same variable that your query results are in, thus replacing it's value. That will cause problems.
Give this a try.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result))
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
add a comment |
up vote
1
down vote
accepted
One thing that I noticed was you were storing your curl result into the variable $result
. That is the same variable that your query results are in, thus replacing it's value. That will cause problems.
Give this a try.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result))
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
One thing that I noticed was you were storing your curl result into the variable $result
. That is the same variable that your query results are in, thus replacing it's value. That will cause problems.
Give this a try.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result))
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
One thing that I noticed was you were storing your curl result into the variable $result
. That is the same variable that your query results are in, thus replacing it's value. That will cause problems.
Give this a try.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result))
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
edited Nov 11 at 2:11
answered Nov 11 at 2:02
Joseph_J
2,9372619
2,9372619
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244702%2flooping-fcm-token-in-curl-script-from-mysql-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You have to wrap a loop around your curl code populating a new token on each iteration.
– Joseph_J
Nov 11 at 1:13
I did, try to wrap around the curl code, (i put the closing curly brace after $result), but it sent the notification to the second FCM TOKEN
– Neliswa Astute
Nov 11 at 1:24
please update your code
– Joseph_J
Nov 11 at 1:37
How many users is this going out too?
– Joseph_J
Nov 11 at 2:04