-2

I have this piece of code:

$user = $_GET["user"];
echo $user;

which outputs:

1234

And the URL looks like this :

http://localhost/getkey.php?user=1234

How can I get multiple variables from the URL separated by a "&"?

For example:

http://localhost/getkey.php?user=1234&password=4321
alexenv
  • 93
  • 1
  • 2
  • 9

2 Answers2

1

To get the values passed in the URL you need to call $_GET['name'] for each value that you want.

Example:

http://localhost/getkey.php?user=1234&password=4321

$user = $_GET['user'];
$password = $_GET['password'];

This way will allow to you to use the value passed in the URL

Daniel Paiva
  • 121
  • 2
  • 10
-1
extract($_GET);

This assigns the values in $_GET to variables with the same names as the keys. Don't do this though - it's much better to be explicit and assign each one of your variables separately so that you can trace what is used where better later and so that you don't run into naming conflicts. For this reason, it is also insecure, because your variables can be overridden by user-defined ones, which could be malicious.

See discussion here: What is so wrong with extract()?

kloddant
  • 1,026
  • 12
  • 19