Check if there is a parameter in the URL by PHP

Asked

Viewed 346 times

0

You guys, here’s the deal...
I need to check if in the url there is a parameter (source) and take the value that is being passed by it...

I tested it like this $param = $_GET["source"]; but if there is no parameter in the url, give an error Notice: Undefined index: source.

How do I only get the parameter if it exists?

  • Caio, you understood with my answer?

  • @Leonardonegrão yes man, thank you very much!

1 answer

1


first check if it exists, so:

if(isset($_GET['source'])) { //existe source?

$param = $_GET['source'];

}
else { //se não existir source, $param terá outro valor

$param = "";

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.