-2

I'm trying to make a page from where I'll send a verification code to the email. Suppose, the mail will contain this link

http://www.something.com/confirmation.php?passkey=123

In the confirmation.php page, I'll write

    $_GET['passkey'];

So, I'll receive the passkey there.

But if someone doesn't provide a passkey and try to to go to the page

http://www.something.com/confirmation.php

they'll see an error like "Notice: Undefined index: passkey in http://www.something.com/confirmation.php on line 7".

Now, I want a code, where if someone provides a passkey, it'll be received. But if someone doesn't provide any passkey, it'll show no error. It will automatically check, if someone has provided a passkey or generally trying to access to the page. How can this be done?

  • 1
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Epodax Mar 01 '17 at 09:29
  • `if(!isset($_GET['passkey'])) die('no passkey');` – Steve Mar 01 '17 at 09:38
  • Thank you. It solved my problem. – Nahid Sultan Mar 01 '17 at 09:54

1 Answers1

1

The error is one provided by PHP because you're trying to use a variable that doesn't exist. You can check this yourself with something simple as this:

if(isset($_GET['passkey'])) {
    // passkey index exists
}

This will check if the passkey is set, not if it is correct though. You'll have to check for the value yourself.

Pim Broens
  • 702
  • 1
  • 5
  • 16