r0naldinio
r0naldinio

Reputation: 191

How to check $_GET isset for a parameter and value?

Let's say I have a link:

https://www.example.com/?name=john

I know how to do something if a specific parameter exists :

<?php if (isset($_GET['name'])) : ?>

What I want is to use if for both, parameter and value.

Basically I want to do like this:

<?php if (isset($_GET['name, john'])) : ?>

Above is just an example. It's doesn't work.

Can anyone guide to the right code for this?

Thanks.

Upvotes: 2

Views: 463

Answers (1)

Gerard de Visser
Gerard de Visser

Reputation: 8050

You first need to check if the parameter is set and after that if parameter equals the expected value.

Like this:

<?php if (isset($_GET['name'])) : ?>
    <?php if ($_GET['name'] === 'john') : ?>
        // Name exists and is john
    <?php endif; ?>
<?php endif; ?>

Upvotes: 2

Related Questions