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
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
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
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
php mysql
edited Nov 11 at 1:15
Frank van Puffelen
220k25361387
220k25361387
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 |
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,6921618
2,6921618
add a comment |
add a comment |
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