Welcome! Log In Create A New Profile

Advanced

Problem with ampersand in the query string

Posted by lobo 
Problem with ampersand in the query string
July 31, 2010 01:49AM
I am struggling with ampersands in the query string.
file.php has only this line:
[code]
echo $_GET['var'];
[/code]


And the URL is http://domain.com/file.php?var=AT&T

Instead of echoing [b]AT&T[/b] the problem is that the script echoes only [b]AT[/b]

This also happens if the URL is http://domain.com/file.php?var=AT%26T

My configuration in server { ... } to handle PHP scripts is as follows:

[code]
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/path/to/dir$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
[/code]

How to make this work?
Jérôme Loyet
Re: Problem with ampersand in the query string
July 31, 2010 06:10AM
2010/7/31 lobo <nginx-forum@nginx.us>:
> I am struggling with ampersands in the query string.
> file.php has only this line:
> [code]
> echo $_GET['var'];
> [/code]
>
>
> And the URL is http://domain.com/file.php?var=AT&T
>
> Instead of echoing [b]AT&T[/b] the problem is that the script echoes
> only [b]AT[/b]

this is normal because & is a separator in URL.

>
> This also happens if the URL is http://domain.com/file.php?var=AT%26T

this should work. But this is a nginx question, not a FPM one. Please ask there.

>
> My configuration in server { ... } to handle PHP scripts is as follows:
>
>    [code]
> location ~ .php$ {
>        fastcgi_split_path_info ^(.+\.php)(.*)$;
>        fastcgi_pass   backend;
>        fastcgi_index  index.php;
>        fastcgi_param  SCRIPT_FILENAME
> /var/www/path/to/dir$fastcgi_script_name;
>        include fastcgi_params;
>        fastcgi_param  QUERY_STRING     $query_string;
>        fastcgi_param  REQUEST_METHOD   $request_method;
>        fastcgi_param  CONTENT_TYPE     $content_type;
>        fastcgi_param  CONTENT_LENGTH   $content_length;
>        fastcgi_intercept_errors        on;
>        fastcgi_ignore_client_abort     off;
>        fastcgi_connect_timeout 60;
>        fastcgi_send_timeout 180;
>        fastcgi_read_timeout 180;
>        fastcgi_buffer_size 128k;
>        fastcgi_buffers 4 256k;
>        fastcgi_busy_buffers_size 256k;
>        fastcgi_temp_file_write_size 256k;
>    }
> [/code]
>
> How to make this work?
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,115095,115095#msg-115095
>
>
Jérôme Loyet
Re: Problem with ampersand in the query string
July 31, 2010 06:22AM
Le 31 juillet 2010 12:08, Jérôme Loyet <ml@fatbsd.com> a écrit :
> 2010/7/31 lobo <nginx-forum@nginx.us>:
>> I am struggling with ampersands in the query string.
>> file.php has only this line:
>> [code]
>> echo $_GET['var'];
>> [/code]
>>
>>
>> And the URL is http://domain.com/file.php?var=AT&T
>>
>> Instead of echoing [b]AT&T[/b] the problem is that the script echoes
>> only [b]AT[/b]
>
> this is normal because & is a separator in URL.
>
>>
>> This also happens if the URL is http://domain.com/file.php?var=AT%26T
>
> this should work. But this is a nginx question, not a FPM one. Please ask there.
>
>>
>> My configuration in server { ... } to handle PHP scripts is as follows:
>>
>>    [code]
>> location ~ .php$ {
>>        fastcgi_split_path_info ^(.+\.php)(.*)$;
>>        fastcgi_pass   backend;
>>        fastcgi_index  index.php;
>>        fastcgi_param  SCRIPT_FILENAME
>> /var/www/path/to/dir$fastcgi_script_name;
>>        include fastcgi_params;
>>        fastcgi_param  QUERY_STRING     $query_string;
>>        fastcgi_param  REQUEST_METHOD   $request_method;
>>        fastcgi_param  CONTENT_TYPE     $content_type;
>>        fastcgi_param  CONTENT_LENGTH   $content_length;
>>        fastcgi_intercept_errors        on;
>>        fastcgi_ignore_client_abort     off;
>>        fastcgi_connect_timeout 60;
>>        fastcgi_send_timeout 180;
>>        fastcgi_read_timeout 180;
>>        fastcgi_buffer_size 128k;
>>        fastcgi_buffers 4 256k;
>>        fastcgi_busy_buffers_size 256k;
>>        fastcgi_temp_file_write_size 256k;
>>    }
>> [/code]
>>
>> How to make this work?

btw which nginx version are you using ?

Here is the test I've just done:

test.php
<pre>
<?php var_dump($_GET); ?>
</pre>

calling http://foo.bar/test.php?var=AT&T outputs:

array(2) {
["var"]=>
string(2) "AT"
["T"]=>
string(0) ""
}

the & is not encoded, so it splits AT&T in two variables.

calling http://foo.bar/test.php?var=AT%26T outputs:

array(1) {
["var"]=>
string(4) "AT&T"
}

the & is encoded, so it doesn't split AT&T in two variables.

I'm using nginx 0.8.40 for this test with the following conf:
location ~ \.php2$ {
root html;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}


>>
>> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,115095,115095#msg-115095
>>
>>
>
Re: Problem with ampersand in the query string
July 31, 2010 06:58PM
nginx version is 0.7.65 and this is the output for nginx -V
[code]
nginx version: nginx/0.7.65
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-mail --with-mail_ssl_module --with-ipv6 --add-module=/build/buildd/nginx-0.7.65/modules/nginx-upstream-fair
[/code]

For the URL index.php?title=D%26B the detailed log is at http://pastebin.com/ThgmBLGU
Re: Problem with ampersand in the query string
August 01, 2010 12:23AM
Never mind. This was a rewrite issue. The URL was not being rewritten correctly. This is solved now.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 86
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready