julia k Posted February 15, 2009 Share Posted February 15, 2009 Hello! I recently ran into a problem, and I have no one to ask for help I have implemented in one of my pages a free script for pagination, which works as expected if the values it requires are passed as they would normally be. For example, the pagination class requires a variable to be set: ?page= and if its value is numeric then it will display the required page. So this part works. Now, if I request the page like this: http://site.com/index.php?page='1 , notice the ' before the numeric value it will break everything that's beneath the pagination's links, ie: the page footer. I was looking for a way to parse the value set in the page variable and retrieve only the numeric value, if any (if I don't get any value, I'll just display the first page) but I couldn't come up with anything... to get the value from this variable, I have the following script: <?php if (isset($_GET['page'])) { $page = (int) $_GET['page']; // it breaks if any other non-numeric values are passed along } ?> Can someone please help a sista' out? Quote Link to comment https://forums.phpfreaks.com/topic/145350-how-to-restrict-a-variable-to-only-numeric-values/ Share on other sites More sharing options...
.josh Posted February 15, 2009 Share Posted February 15, 2009 well if someone is putting something like that in the url then they are probably trying to break it in the first place, and that 1 in '1 would just be some arbitrary value. Instead of trying to filter out a number in the midst of an obvious attack attempt, simply display a default page number if it's not a positive integer within the page range. Quote Link to comment https://forums.phpfreaks.com/topic/145350-how-to-restrict-a-variable-to-only-numeric-values/#findComment-763053 Share on other sites More sharing options...
julia k Posted February 15, 2009 Author Share Posted February 15, 2009 roger that! less work for php too thanks Quote Link to comment https://forums.phpfreaks.com/topic/145350-how-to-restrict-a-variable-to-only-numeric-values/#findComment-763055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.