MOS
MOS

Reputation: 31

Finding whether a $_GET variable is a numeric string

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";
}

Upvotes: 0

Views: 96

Answers (1)

Blaise
Blaise

Reputation: 340

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'

Upvotes: 1

Related Questions