0

I tried requests module but I've error in my php outputs: The error is: Notice: Undefined index: firstname in D:\xampp\htdocs\myfile\receive.php on line 7 NULL

code in python:
'''
payload = {'firstname':'Jack'}
url = "http://localhost/myfile/receive.php"
resp = requests.post(url, data=payload)
print(resp.status_code)
text =resp.text
print(text)
'''
status_code is ok(200)!

php code:
$data = $_POST["firstname"];
var_dump($data);

It seems okay but it's not :)

6
  • Try var_dump($_POST); to see what you get in php script. Commented Sep 22, 2021 at 2:45
  • please use isset() when handling POST / GET / COOKIE / SESSION variables Commented Sep 22, 2021 at 2:53
  • Not sure what the python code will send your payload as - is it sending it as JSON, perhaps? Then you would have to receive it differently in PHP - stackoverflow.com/questions/18866571/receive-json-post-with-php Commented Sep 22, 2021 at 8:05
  • P.s., please go read meta.stackoverflow.com/questions/251361/… Commented Sep 22, 2021 at 8:05
  • @Lessmore the output of python is: <br/> 'array(1) { ["firstname"]=> string(4) "jack" } ' <br/> but my browser shows me: ' array(0) { }' Commented Sep 23, 2021 at 3:48

1 Answer 1

0

In your php code, you have to use $_REQUEST["firstname"];

$data = $_REQUEST["firstname"] 

instead of using $_POST

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.