checking if a variable is an int and within a range

Associate
Joined
2 Aug 2005
Posts
680
I've got a little script on my site where it will display an included article from a variable passed from the url, but I can't get it working properly. Here's the code:

Code:
if ($article <= 6 || is_int($article)) {
	$displayArticle = 'article' . $article . '.inc.htm';
	} else {
	$displayArticle = 'article.inc.htm';
	}

So the page url will be something like foo.php?article=2
But I don't want it to include if the article= something other than a valid number or a string of text etc. Any help appreciated :)
 
PHP:
<?php

$article = (int) $_GET['article']; 
// $article will be 0 if user entered a non-numeric value

if ( $article <= 6 ) {
    // whatever
} else {
    // whatever
}

?>
 
Thanks for that, it seems to be doing the trick but the article0 isn't displaying, I'm getting this message:

Warning: main(article0.inc.htm): failed to open stream: No such file or directory
and the file is in there. Is there any way to stop this?

Thanks
 
Back
Top Bottom