1

When I run

if (filter_var($_GET['abc'], FILTER_VALIDATE_URL)) { ... }

and I don't give a ?abc= extension to my .php then I get notice:

Notice: Undefined index: abc in line...

Is there a way to bypass this notice and say if $_GET exists and then is abc then...

Thanks a lot

George G
  • 7,443
  • 12
  • 45
  • 59

3 Answers3

4

You have to test if key abc in GET exists, so:

if (isset($_GET['abc']) && filter_var($_GET['abc'], FILTER_VALIDATE_URL)) { ... }
pavel
  • 26,538
  • 10
  • 45
  • 61
3
if (isset($_GET['abc']) && filter_var($_GET['abc'], FILTER_VALIDATE_URL)) { ... }

This way it checks if that exist and you won't get a notice , hope this help :)

peterpeterson
  • 1,315
  • 2
  • 14
  • 38
3

you have to check whether the index is set using isset

if (isset($_GET['abc']) && filter_var($_GET['abc'], FILTER_VALIDATE_URL))
Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101