0
How to use post in php? [SOLVED]
I have virtual web (centos 6.10, php version 5+) and I'm trying to make request with post, however array $_POST is empty, Somebody know what could solve this?
18 ответов
+ 1
With forms(application/x-www-form-urlencoded), it should work if method="post".
However $_POST does not work for other Content-Type. You have to manually read 'php://input' stream.
Can you share the php code? Also verify that your form's method is POST.
+ 1
Are you sure there is an input field with name="user" in the submitted form?
+ 1
+ 1
Try to manually read php://input stream. It should contain the said data.
+ 1
Hmm 🤔
+ 1
nicolas turek I know it is JS. I was talking about your PHP. According to you, 'files' and 'files/' both point to the same route but 'files' (without slash) does not send the posted data. To me, that is a flaw in the routing system of your website. You should either return a 404 response or trim the extra slash.
0
How are you making the request?
0
I tried form and xmlhttprequest (with get it works)
0
Versions:
Php 5.3.3, Apache 2.2.15
0
Php:
<?php
if(isset($_POST["user"]))echo "ok";
else echo "ko";
?>
0
I tried it with get
0
Problem is in post, not way I get things to there, I think it could be something with server
0
Thanks for this, no solution worked sadenly
0
Ok, I find solution by myself - it's really stupid: there has to be / at the end of url :D
0
My first request open part was (not working):
req.open("POST", "files", true);
Working:
req.open("POST", "files/", true);
0
nicolas turek Are you using a router script or relying on file system based routing?
0
No, that's js, just I'm lazy writing whole script, only thing you need to know, that req is instance object of xmlhttprequest
0
The thing I'm doing include json files, so I don't think it's possible to do it with sololearn