0

I am doing GET request like this:

//url = http://localhost/api/login.php/?name=max

if(isset($_GET['name'])){
  echo "Hi ".$_GET['name'];
}else{
  echo "Error";
}

But I am unable to fetch data from POST request.

//url = http://localhost/api/login.php/?name=max

if(isset($_POST['name'])){
  echo "Hi ".$_POST['name'];
}else{
  echo "Error";
}

How can I get post data.

RajB009
  • 417
  • 2
  • 7
  • 19

2 Answers2

0

$_POST data is read from the body of the request if the content-type is set to application/x-www-form-urlencoded or multipart/form-data. You can also read the request body via the php://stdin stream.

Data is not read from the query string, like $_GET.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
0

You cant get $_POST data from the url, what you can do is this;

<form action="http://localhost/api/login.php" method="post">
<input type="hidden" name="name" value="max">
<input type="submit">
</form>

Or if you want people to set their name;

<form action="http://localhost/api/login.php" method="post">
<input type="text" name="name" value="max">
<input type="submit">
</form>

It's pretty simple and clear :)