2

I'm trying to develop a web server with PHP support so I'm doing some little tests with php-cgi, but I can't pass to the interpreter $_POST values. I've already read this topics, but I couldn't do anything :(:

My source:

export GATEWAY_INTERFACE="CGI/1.1"
export SCRIPT_FILENAME="/home/xzhttpd/htdocs/test.php"
export REQUEST_METHOD="POST"
export REDIRECT_STATUS=200
export SERVER_PROTOCOL="HTTP/1.1"
export REMOTE_HOST="127.0.0.1"
export CONTENT_LENGHT=3
export HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
export CONTENT_TYPE="application/x-www-form-urlencoded"
export BODY="t=1"

exec echo "$BODY" | /usr/bin/php-cgi

I got this:

PHP Notice: Undefined index: t in /home/xzhttpd/htdocs/test.php on line 1

PHP source:

<?php print $_POST["t"]; ?>
Community
  • 1
  • 1
alkz
  • 337
  • 2
  • 7
  • 17

2 Answers2

4

You're missing a few more crucial CGI environment variables (it's best to set all of them), which when absent make PHP ignore the request and POST body:

export SCRIPT_NAME="xy.php"
export REQUEST_URI="/xy.php"
export SERVER_NAME="example.com"
export SERVER_PROTOCOL="HTTP/1.1"

That will lead to another PHP warning due to REDIRECT_STATUS=. (Don't remember how that works, probably requires more REDIRECT_* aliases, but one could just disable force-cgi-redirect in the php.ini for testing.)

mario
  • 144,265
  • 20
  • 237
  • 291
4

You have CONTENT_LENGHT misspelled.

It should be CONTENT_LENGTH

Naftali
  • 144,921
  • 39
  • 244
  • 303