Jump to content


Photo

$_GET variables


  • Please log in to reply
6 replies to this topic

#1 S4C

S4C
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 17 July 2006 - 01:20 PM

Hmm how to be sure that my $_GET['page'] is really integer..?
Thanks

#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 17 July 2006 - 01:21 PM

http://ca3.php.net/m...tion.is-int.php

is_int is your friend.

Edit:

http://ca3.php.net/m....is-numeric.php
is_numeric

use is_numeric if the value you wish to test is of a string data type.
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 01:23 PM

Anything sent through $_GET is technically a string, but you could try to force it into being an integer by using typecasting. eg;
if (isset($_GET['page'])) {
  $page = (int) $_GET['page'];
}
Or you might just check it using [url=http://php.net/is_numeric[/url]().

#4 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 July 2006 - 01:24 PM

The method above will turn a string of text sent via the $_GET into 0, FYI

#5 S4C

S4C
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 17 July 2006 - 01:24 PM

Thanks a lot guys.  ;)

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 17 July 2006 - 01:25 PM

is_int checks only if the variable is an integer.
But if the number is being transfered using GET, POST etc', the variable will be a string of number/s.
So you need to use is_numeric().

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 17 July 2006 - 01:25 PM

You can use is_numeric, convert to intval and is_int after each other to check.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users