-2

As I understand a php POST method can be passed through the url

File name: test.php

<?php

if(isset($_POST['id']{
     echo'Great';
}else{
     echo'Why ?';
 }

 ?>

When I put manually in the browser /test.php?id=value it always returns the else statement

Why ?

T.Galisnky
  • 79
  • 1
  • 11
  • caue your doing a get request not a post – Abslen Char Mar 24 '18 at 22:18
  • Because if you do it in the browser-URL it is a `$_GET['id']`. – deEr. Mar 24 '18 at 22:18
  • Regardless whether you make a POST or a GET request, query variables added to the url will be available in `$_GET` and not `$_POST`. – jeroen Mar 24 '18 at 22:18
  • Thanks for the answer, really appreciate it How would I tell the browser to make a POST request ? – T.Galisnky Mar 24 '18 at 22:21
  • You post a form (with the correct method set...) for example or you use javascript to make a POST request. – jeroen Mar 24 '18 at 22:22
  • all parameters that are puts in the URL like you have done are retrieved by using the `$_GET` global variable, and in you case you must use `isset($_GET['id']`) as the condition instead of what you have put in you if condition – Yves Kipondo Mar 24 '18 at 22:22

3 Answers3

2

Because, below line of code is equivalent to GET method not POST

 /test.php?id=value

And, since $_POST['id'] value was not set, it will return false. You need to check isset($_GET['id']) instead.

Ravi
  • 30,829
  • 42
  • 119
  • 173
0

That's because test.php?id=value in the browser is a GET method, not POST.

You can always get the value with $_GET

crashxxl
  • 682
  • 4
  • 18
0

If you want make secure, use $_REQUEST['id']

This works for GET and POST

Eliseo
  • 604
  • 4
  • 10