-1

Good day,

I would like to know if there is any function for making the difference between this:

?param=

and this:

?param

Because I would like my script to detect if value is empty (first example), or if it's not given (second example).

I made a test with the following functions but I could not find what I want:

if( isset( $_GET['param'] ) ) {
    echo '<div>isset</div>';
    
    if( empty( $_GET['param'] ) ) {
        echo '<div>empty</div>';
    } else {
        echo '<div>not empty</div>';
    }
    
    if( is_null( $_GET['param'] ) ) {
        echo '<div>null</div>';
    } else {
        echo '<div>not null</div>';
    }
    
    if( defined( $_GET['param'] ) ) {
        echo '<div>defined</div>';
    } else {
        echo '<div>undefined</div>';
    }
} else {
    echo '<div>not set</div>';
}

Any idea? Thank you in advance.

EDIT

Solution:

( strpos( '?'.$_SERVER['QUERY_STRING'], '?get=' ) !== false ) || ( strpos( '?'.$_SERVER['QUERY_STRING'], '&get=' ) !== false )
Lucas F
  • 15
  • 6
  • 3
    You need to parse `$_SERVER['QUERY_STRING']` yourself, you can't distinguish them in `$_GET`. – Barmar Feb 02 '22 at 16:03
  • What I guessed, thank you @Barmar – Lucas F Feb 02 '22 at 16:09
  • https://stackoverflow.com/questions/12503364/how-do-i-check-if-a-get-parameter-exists-but-has-no-value – mark_b Feb 02 '22 at 16:37
  • The variable is only null if it's not set or retrieved directly from filter raw [see filter_input() for reference](https://www.php.net/manual/en/function.filter-input). What you can check for is that it's set but empty. That's the only notable difference. – Sherif Feb 02 '22 at 17:22

1 Answers1

0

You can test with something like if( $_GET['param'] ) which will give true if Param is declared (even if it is an empty string) and false if not declared.