Home  >  Article  >  Backend Development  >  After the project was changed to Linux, were the $_GET[] input parameters urlencoded by default? ? ?

After the project was changed to Linux, were the $_GET[] input parameters urlencoded by default? ? ?

WBOY
WBOYOriginal
2016-12-01 00:25:421196browse

It turns out

Server: Win2003 + IIS runs normally without problems
Local: Win10 + apache and Win10 + nginx runs normally without problems

Now

The project recently replaced Alibaba Cloud CentOS7.2 and nginx1.10.2; a problem occurred.

Specific questions (the project is written in ThinkPHP3.2.3)

There is a Form form in the page for search, and the get data for search. After clicking the button, the following URL is formed

<code>/index.php/User/index.html?key=刘</code>

I use I('key') (TP-encapsulated method of obtaining input variables similar to $_GET['key']) in the controller to obtain this keyword, and then query and paginate; the page number link generates a URL similar to the following

<code>/index.php/User/index/key/刘/p/2.html</code>

When clicking the page number link above to turn the page:

  • No matter how you get the key locally or from the original server, the key is string "Liu"

  • But on the new server, the keyword obtained is string "%e5%88%98"

This resulted in all my original programs with this kind of search being ineffective and unable to turn pages.

Solutions I tried

  • I('key') uses urldecode when getting the data, but I found that I can only turn one page. If I do it again, the key will be urlencoded again. No matter how many times I turn it, it will be urlencoded infinitely

  • Since the url pattern cannot be modified, I gave up this method

Why?

Win+IIS Win+nginx is no problem. Why does this problem occur when using linux+nginx? Is this the fault of me, Linux, or nginx? Please advise.

We are very urgent to get the project back to normal, please help me with the answers

Reply content:

It turns out

Server: Win2003 + IIS runs normally without problems
Local: Win10 + apache and Win10 + nginx runs normally without problems

Now

The project recently replaced Alibaba Cloud CentOS7.2 and nginx1.10.2; a problem occurred.

Specific questions (the project is written in ThinkPHP3.2.3)

There is a Form form in the page for search, and the get data for search. After clicking the button, the following URL is formed

<code>/index.php/User/index.html?key=刘</code>

I use I('key') (TP-encapsulated method of obtaining input variables similar to $_GET['key']) in the controller to obtain this keyword, and then query and paginate; the page number link generates a URL similar to the following

<code>/index.php/User/index/key/刘/p/2.html</code>

When clicking the page number link above to turn the page:

  • No matter how you get the key locally or from the original server, the key is string "Liu"

  • But on the new server, the keyword obtained is string "%e5%88%98"

This resulted in all my original programs with this kind of search being ineffective and unable to turn pages.

Solutions I tried

  • I('key') uses urldecode when getting the data, but I found that I can only turn one page. If I do it again, the key will be urlencoded again. No matter how many times I turn it, it will be urlencoded infinitely

  • Since the url pattern cannot be modified, I gave up this method

Why?

Win+IIS Win+nginx is no problem. Why does this problem occur when using linux+nginx? Is this the fault of me, Linux, or nginx? Please advise.

We are very urgent to get the project back to normal, please help me with the answers

In the source code of TP paging, urlencode operation is performed when generating the URL

<code>private function url($page){
        return str_replace(urlencode('[PAGE]'), $page, $this->url);
    }</code>

Solution: You can pass the search parameter as the third parameter when instantiating the paging class. For details, please view the construction method of the Page class

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn