-1

I get variable from http://localhost/match?id=1 via code:

<?
if (isset($_POST['id'])) {
    $id = $_POST['id'];
    $id = secure($id);
} else {
    echo "error";
    die();
}

And I get the error from my else statement. How to get the parameter, passed via the link?

userlond
  • 3,323
  • 2
  • 28
  • 45
Loleris54
  • 35
  • 5
  • 4
    If you're trying that through a browser `....?id=1` will make it a GET request, and thus you won't see anything in `$_POST`. If you need to do a POST request, you [can use curl](https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request) to test it with. – Marios Hadjimichael Jul 13 '17 at 01:58
  • Read [this](https://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get) for more details on GET vs POST. – Marios Hadjimichael Jul 13 '17 at 02:00
  • Also, in case you simply don't care if it's a GET or POST request, you can use `$_REQUEST['id']`. – Marios Hadjimichael Jul 13 '17 at 02:01
  • Possible duplicate of [What is the difference between POST and GET?](https://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get) – chris85 Jul 13 '17 at 02:09

2 Answers2

0

Try this code:

<?
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $id = secure($id);
} else {
    echo "error";
    die();
}

Params, passed throught the link, are accessable trough the $_GET superglobal.

Info about $_GET on php.net.

Some explanations about $_GET vs $_POST on w3schools.com.

userlond
  • 3,323
  • 2
  • 28
  • 45
-1

use POST if you get data from form. and GET if you get data by link. in your case it is link

if (isset($_POST['id'])) { ** this POST should be GET because you have http://localhost/match?id=1
magma
  • 1
  • 2