3

in relation to php int64 limits, if the uri has a int64 argument, how do you prevent GET from wrongly converting it into numeric and simply keeping it as a string?

http://some.com?id=1707541557936130

then

echo $_GET['id'] => 1.7075415579361E+15

how to prevent this and have $_GET['id'] be the string 1707541557936130?

the way $_GET works now is unusable. need to parse $_SERVER["QUERY_STRING"] myself. but then never know when php will grab a variable and incorrectly convert again.

NOTE: afaik this will be a problem on 32bit, not 64bit php installs.

Community
  • 1
  • 1
cc young
  • 18,939
  • 31
  • 90
  • 148

4 Answers4

4

Everyrthing coming out of _GET/_POST/_COOKIE is a string. That data wouldn't be converted to a number unless you did something that forced it to be interpreted as one.

echo $_GET['id']; // echoes your big number
echo $_GET['id'] + 0; // forces an int conversion
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

This should get the job done.

echo (string) $_GET['id'];
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
Stefan
  • 2,961
  • 1
  • 22
  • 34
0

bite the bullet and install 64bit - it's what's on your server anyway

cc young
  • 18,939
  • 31
  • 90
  • 148
0

If the current solutions are not working you can append a string character to the integer such as

http://some.com?id=i1707541557936130

Additionally, if it is an issue of how the float is displayed you can use number_format().

$id = (string) number_format($_GET['id']);
echo $id;
Steve Buzonas
  • 5,300
  • 1
  • 33
  • 55
  • yes, thought about prepending the ID with an alpha, just as you suggested. but soon as you use it, eg, `$id = substr($id,1)`, you never know when php is going to stab you in the back and force a coercion on you. the `number_format()` does not fly since the precision has already been lost – cc young Jan 04 '12 at 15:34
  • What are you doing with the number? Can you split it from the string into an upper and lower half before you manipulate it? – Steve Buzonas Jan 04 '12 at 21:30