F
F
Fedor Ananin2016-10-09 00:31:07
PHP
Fedor Ananin, 2016-10-09 00:31:07

Data is not transmitted by the POST method, how to fix it?

Goodnight!
I can not understand the essence of the problem. There is an Apache + Nginx + php5.6 server, there is a simple script:

<?php
  if ($_GET['ok']==''){
    echo "<form action='?ok=ok' method='post'>
    <input type='text' name='login' placeholder='Логин'><br>
    <input type='text' name='password' placeholder='Пароль'><br>
    <input type='submit' value='OK'><br>
    </form>";
  }else{
    echo $_POST['login'];
  }
?>

Everything works on LAN, but not on a server.
I tried to turn off register_globals, climbed into magic quotes, I don’t know why, but I simply have no idea what the problem is.
Tell me, please, why I am not transmitting data using the POST method ... If you select the GET method, then everything works.
UPD
The search showed that the $_POST array is empty.
Through .htaccess and php.ini I changed different values: from register_global to php_flag enable_post_data_reading On and php_value variables_order "GPCS"
phpinfo() says that all settings are exactly the same.
Through php://input the data is visible.
var_dump($_SERVER); shows that REQUEST_METHOD => GET. And should be POST.
I managed to get everything working through a hack:
$postdata = file_get_contents("php://input");
$postdata=explode('&', $postdata);
foreach ($postdata as $k=>$v){
  $v=explode('=', $v);
  $_POST[$v[0]]=urldecode($v[1]);
}

Looks terrible, but at least it works. It is very necessary to give the client access to the site's admin panel... The authorization data comes by the POST method, and the $_POST array is empty, so I'm perverting as best I can.
It turns out that the problem is in the apache + nginx bundle, right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2016-10-09
@slo_nik

Good evening.
The first line, always, forever - error_reporting(E_ALL);
Turn on the output of all errors that are possible.
And then start writing code!
Set the action attribute to a value if the form and the handler are in the same file, then just try #
In the if ($_GET['ok']=='') or if ($_POST['ok']=='') line there will be a warning , because such arrays do not exist initially. Only after submitting the form can you receive any of them.

if(isset($_POST)){
   // делаем что-то
}
else{
 // выводим форму
}

A
Alexey, 2016-10-09
@alsopub

Do this:

<?php
  if ($_POST['ok']==''){
    echo "<form action='?' method='post'>
    <input type='hidden' name='ok' value='ok'>
    <input type='text' name='login' placeholder='Логин'><br>
    <input type='text' name='password' placeholder='Пароль'><br>
    <input type='submit' value='OK'><br>
    </form>";
  }else{
    echo $_POST['login'];
  }
?>

Well, or you can add name="ok" to the submit button instead of a hidden field.

G
Geeeek, 2018-10-09
@Geeeek

if(count($_POST) > 0){
}else{
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question