0

I am trying to prove that $_GET['start'] is a number, but I am getting that it is not.

I also need to make the value of $start not bigger than 10.

$number = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g', 'j');
$start = 2;
$len = isset($_GET['len']) ? (int) $_GET['len'] : 2;
$s = isset($_GET['start']) ? (int) $_GET['start'] + 2 : 4;

foreach($number as $value) {
    print_r($value);
}
echo '<br>' . '<br>';

if(isset($_GET['start']))
    $start = $_GET['start'];

foreach(array_slice($number, $start, $len) as $k) {
    print_r($k);
}
echo '<br>' . '<br>';

if(is_numeric($_GET['start'])) {

    echo '<a href="http://192.168.1.6/alpha.php?start=' . $s . '&len=2">
                                    continue</a>';
}

else {
    echo "not a nummber";
}
3
  • 1
    You could validate or sanitize the value. Commented Aug 9, 2017 at 16:12
  • 1
    as @Blaise said, did you mean to use the $start variable? Are you sure that you are passing the variable as a GET? Commented Aug 9, 2017 at 16:35
  • I agree, this already seems to work. Can you add a bit more explanation of the problem? Commented Aug 9, 2017 at 16:42

1 Answer 1

1

I inputted your code into a test server, and it worked for me as is. However, your code doesn't define $_GET['start'], so make sure that your test url includes ?start=2.

You can test it for yourself by typing $_GET['start']=2 or even $_GET['start']='2'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.