If i am sending data in query params from angular application i need to get those data in php from url. I am not familiar to php. Can anyone help me out yr?
Asked
Active
Viewed 148 times
0
-
Have you tried googling it? You look like you know what you want to do, we are here to help if you get stuck, come back and edit your question once you have tried something – Dev Man Nov 22 '21 at 06:52
2 Answers
1
Pass a link in url for testing let say localhost/test/test.php?link=www.google.com
<?php
echo $_Get['link'];

Anuj Todankar
- 168
- 11
-
This would produce: Undefined variable: _Get . You should use `$_GET` – sukalogika Nov 22 '21 at 07:07
-
@sukalogika i am using $_Get it is giving me correct result. But if the url contains "&" then the result comes what ever data is there before &. Is it any way to fetch data with &. – Anuj Todankar Nov 22 '21 at 07:10
-
You should use encode that string. https://stackoverflow.com/questions/4744888/how-to-properly-url-encode-a-string-in-php – sukalogika Nov 22 '21 at 07:19
1
In your php file, check to see that you got the needed parameter. If so, handle the call as you wish. Otherwise, you can send back an error. An example: If your query param is called "someParameter", then
<?php
if (isset($_GET['someParameter'])) {
$someParameter = $_GET['someParameter'];
// Do something with it
}
else {
$httpStatusCode = 400;
$httpStatusMessage = 'someParameter is missing';
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
header($protocol.' '.$httpStatusCode.' '.$httpStatusMessage);
}
?>

Shem
- 258
- 2
- 8