开发者

Empty $_GET despite the URL

$_GET variable shows empty on the URL www.abc.com/ec/basket.php?product_id=1.

This is very surprising as $_GET does show value on a different domain with the same URL on the same server. Of course the code is a copy of the original domain.

I am baffled as to why is this happening. Even the first line of the code shows blank $_GET.

When I did print_r($_SERVER) on the first line of the page, I get the following response. The first two values are surprising.

Array
(
    [REDIRECT_REDIRECT_REQUEST_METHOD] => GET
    [REDIRECT_REDIRECT_STATUS] => 404
    [REDIRECT_STATUS] => 404
    [HTTP_HOST] => www.abc.com
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.27 (KHTML, like Gecko) Chrome/12.0.712.0 Safari/534.27
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
    [HTTP_ACCEPT_LANGUAGE] => en-GB,en-US;q=0.8,en;q=0.6
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
    [HTTP_COOKIE] => [various values]
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] => Apache/2.2.3 (Red Hat) Server at www.abc.com Port 80


    [SERVER_SOFTWARE] => Apache/2.2.3 (Red Hat)
    [SERVER_NAME] => www.abc.com
    [SERVER_ADDR] => [IP address]
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => [IP address]
    [DOCUMENT_ROOT] => /var/www/htdocs
    [SERVER_ADMIN] => webmaster@abc.com
    [SCRIPT_FILENAME] => /var/www/htdocs/index.php
    [REMOTE_PORT] => 39746
    [REDIRECT_URL] => /page-not-found.html
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /ec/basket.html?product_开发者_如何学编程id=1
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [PHP_AUTH_USER] => 
    [PHP_AUTH_PW] => 
    [REQUEST_TIME] => 1301662577
)

HTTP status on this shows 404 but the page comes up properly. Just that I am not able to get any values in the $_GET variable.

Also the $_GET variable works perfectly fine on other pages on the same site.

I have been scratching my head on this since hours but cannot find a solution. Any help will be highly appreciated.


You should just have a look to your .htaccess file and look more precisely the line containing the RewriteRule.


Your rewrite rule is probably missing the query string append flag.

Find the line that looks like this:

RewriteRule somestuff index.php [L]

Replace it with:

RewriteRule somestuff index.php [L,QSA]


Put this in your .htaccess file. This will work then.

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{QUERY_STRING}                     ^(.*)$
RewriteRule ^/ec/basket.html?$                  index.php%1


RewriteRule (.*)\.html$ index.php?%{QUERY_STRING} 

Your script or apache does a redirection without passing the GET variables (query string).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜