0

I have an url that I call in this form :

http://MyIP/MyServer/php_scripts/test_sp.php?param1=key&param2=xyz5

and I would like to retrieve the value of the 'param1' and 'param2' parameters. Up to now, I was not successful, because all I get is an empty value.

Sure that I am certainly doing something wrong there, but is it with the way I am calling the url or in my php code itself? Any help will be highly appreciated. Thanks a lot for reading me.

The code below is the contents of my 'test_sp.php' file :

<html>
<head>
</head>
<body>
<?php

mainProcess();

function mainProcess()
{
$mavalue1 = "";
$mavalue2 = "";

$parts = parse_url($url, PHP_URL_QUERY);   // << It looks like I also have a problem with this line.
parse_str($query, $params);
$mavalue1 = $_GET['param1'];
$mavalue2 = $_GET['param2'];

echo "Valeur de mavalue1 : " . $mavalue1;   // <<< This is where I'm getting the empty value
echo "Valeur de mavalue2 : " . $mavalue2;   // <<< Same problem here
}   
?> 
</body>
</html>
Laurent
  • 711
  • 2
  • 12
  • 30
  • 2
    those are GET parameters, so you'll want to use the `$_GET` superglobal with the parameter name, like this: `$_GET['param1']` – Timothy Fisher Feb 16 '17 at 22:42
  • It looks like that I have a problem with my variable url, but I was expecting that if I'm calling the url from the browser, this url would be know. Or ? – Laurent Feb 16 '17 at 22:46

2 Answers2

2

The $_GET array is an array with all the arguments passed in the URL.
You can use $_GET['param1']; to get the value of "param1" in the URL.

Have a nice day.

Ad5001
  • 748
  • 5
  • 19
1
$mavalue1 = $_GET['param1'];
$mavalue2 = $_GET['param2'];
dsmatilla
  • 107
  • 3
  • 1
    While answers are always appreciated, it really helps to provide some information about how your code solves the problem at hand. Please provide some context surrounding your answer, and see the [help article](http://stackoverflow.com/help/how-to-answer) for information on how to write great answers. – Obsidian Age Feb 16 '17 at 23:01