Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM/Parse push function works when using string literal but not string variable

Bit of a weird one, trying to use Parse to push notifications to a device by deviceToken.

If I specify the deviceToken literally, i.e.

$query->equalTo("deviceToken", "uniquedevicetoken");

or

$token = "uniquedevicetoken";
$query->equalTo("deviceToken", $token);

The push works fine without a hitch.

However, If I attempt to use the token from the database, i.e

$query->equalTo("deviceToken", $user->gcm_regid);

The function is not called, even though if I echo out the raw string and the variable together they appear identical.

Also I tried strcmp() which returns 2.

So even though the characters appear visually identical, one works and one does not.

The tokens are stored in MySQL, I have tried VARCHAR and TEXT with a few different encondings, same result every time.

like image 577
BrendanDodd Avatar asked Jun 14 '26 23:06

BrendanDodd


1 Answers

The good solution would be to write in the database "gcm_regid" w/o "special" characters, because it always makes sense to care about sanitization before, so the database will stay "clean". But as a fast solution you can try this:

$query->equalTo("deviceToken", rtrim($user->gcm_regid));
like image 156
Axalix Avatar answered Jun 17 '26 14:06

Axalix