Benjamin Oats Benjamin Oats - 1 month ago 16
PHP Question

Check if URLquery match

I have a URL query within

get.php?&uniId=2
I have code that checks if url string is present.

However my if statement dose not seem to be working correctly

<?php

if(empty($_GET {"uniId=3"})) {
echo "you are able to accsess this page !";

var_dump($_REQUEST);

} else {
echo "sorry no access for you";
}


if i type in http://localhost/mysite/get.php?&uniId=3

I get

echo "you are able to accsess this page !";


and if i type in http://localhost/mysite/get.php?&uniId=2

I get

echo "you are able to accsess this page !";


not

echo "sorry no access for you";

Answer

Just check if the key exist first and than, check the value :

i.e. :

//check if the key exists
if(!empty($_GET{"uniId"})) {
    // check if the value = 3
    if ($_GET{"uniId"} == 3) {
        // do stuff if result is true
    } else {
        // do stuff if result is false
    }
} else {
    echo "The key \"uniId\" does not exists";
}

Hope it helps.