Jump to content

Archived

This topic is now archived and is closed to further replies.

S4C

$_GET variables

Recommended Posts

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

Share this post


Link to post
Share on other sites
http://ca3.php.net/manual/en/function.is-int.php

is_int is your friend.

Edit:

http://ca3.php.net/manual/en/function.is-numeric.php
is_numeric

use is_numeric if the value you wish to test is of a string data type.

Share this post


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

Share this post


Link to post
Share on other sites
The method above will turn a string of text sent via the $_GET into 0, FYI

Share this post


Link to post
Share on other sites
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 [b]string[/b] of number/s.
So you need to use [url=http://www.php.net/manual/en/function.is-numeric.php]is_numeric()[/url].

Orio.

Share this post


Link to post
Share on other sites
You can use [b]is_numeric[/b], convert to [b]intval[/b] and [b]is_int[/b] after each other to check.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.