私はちょうどubuntu 16.04、nginx 1.10.3、php 7.0で新しいvpsをスピンアップし、私の作業サイトをコピーしました。古いサイトはphp5.6にあり、完璧に動作しました。
問題は、コード化されたプラス記号をスペースに変換していることです。 私は、ドキュメントインスペクタを使用して、それが本当の要求は%2Bと+をコードされていることを証明することができますが、まっすぐに、カールのテストも失敗します。これを引き起こすか、またはそれがnginxのですPHP拡張は
Test 1:
curl "my_https_url" --data "details=asdf+%2B+asdf" --compressed
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 2:
curl "my_https_url" --data-urlencoded "details=asdf+%2B+asdf" --compressed
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 3:
$.post("my_https_url",{details:"asdf + asdf"})
Document Inspector Encoded Form Data: details=asdf+%2B+asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 4:
$.post("my_https_url",{details:"asdf %2B asdf"})
Document Inspector Encoded Form Data: details=asdf+%252B+asdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 5:
$.post("my_https_url",{details:"asdf+%2B+asdf"})
Document Inspector Encoded Form Data: details=asdf%2B%252B%2Basdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 6:
$.post("my_https_url",{details:encodeURI("asdf + asdf")})
Document Inspector Encoded Form Data: details=asdf%2520%2B%2520asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 7:
$.post("my_https_url",{details:encodeURIComponent("asdf + asdf")})
Document Inspector Encoded Form Data: details=details=asdf%2520%252B%2520asdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 8:
$.post("my_https_url",$('<form><input name="details" value="asdf + asdf"></form>').serialize())
Document Inspector Encoded Form Data: details=details=details=asdf+%2B+asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 9:
$.post("my_https_url",encodeURIComponent($('<form><input name="details" value="asdf + asdf"></form>').serialize()))
Document Inspector Encoded Form Data: details%3Dasdf%2520%252B%2520asdf
array(0) {} <-- not working
<?php
var_dump($_POST);
// I am expecting "asdf + asdf"
ありますか?私は両方のconfigsを含んだ。
のphpinfo:https://ibb.co/jZCxeQ
nginxの設定:
server {
listen 80;
# access_log /var/log/nginx/website.access_log;
error_log /var/log/nginx/website.error_log;
set $oldhost $host;
root PHP_FILES_LOCATION;
location ~* \.(?:ico|css|js|gif|jpg|png|html|htm)$ {
try_files $uri $uri/ /index.php;
expires 3d;
add_header Pragma public;
add_header Cache-Control "public";
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location/{
index index.php index.htm index.html;
try_files $uri $uri/ /index.php;
}
location ~ json.php$ {
try_files $uri $uri/ /index.php;
# location ~ \..*/.*\.php$ {return 404;}
# expires 3d; add_header Pragma public; add_header
# Cache-Control "public";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
# fastcgi_index index.php;
client_max_body_size 80m;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .php$ {
#location ~ \..*/.*\.php$ {return 404;}
try_files $uri $uri/ /404.php?$args;
#expires 1d;
add_header Pragma public;
client_max_body_size 80m;
add_header Cache-Control "public";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
エンコードされたURLで '+'の意味を認識しているかどうかは不明ですか?そうでない場合はhttps://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20をご覧ください。 – alexis
はい、URLのプラス記号はスペースを表すことができます。だから私はスペース符号化されたバージョン%2Bを送ったのですが、それは決してスペースとして扱われるべきではありません。 –
'--data-urlencode" details = asdf asdf "'を試したことがありますか? –