Example solves the problem that Nginx does not support PATHINFO in TP

Source: Internet
Author: User
Nginx is not supported in TP PathInfo, how to solve it? This article mainly describes how to solve the problem when Nginx does not support PathInfo. We hope to help you.

The following small series by text plus code to the way you explain below, the specific content as follows:

In fact, to solve the problem of Nginx does not support pathinfo, there are two solutions, one is not to use PathInfo mode, the second is to modify Nginx configuration file, so that it supports pathinfo. In order to simplify the problem, I chose the first way, because on the second way, I looked at a lot of information, found that everyone's methods are not the same, some are very different, easy to cause misleading, so I choose to start from the simple, choose the normal mode, although there is a certain risk. When the index.php corresponding to the foreground code modified, found that the front desk is basically normal, but the background still has the problem of redirection. Toss for a long time, I just thought to look at the log file, the original editor is the problem, it seems that the log file is really important, has not been attached to the past. The output appears on the first line of the config.php file,

In the sublime, the general will be added to the UTF-8 file BOM header, the BOM head under the window is usually invisible, can be seen through other editors, Linux can also be directly seen, usually shown to be a garbled character, the character can be deleted, or simply, Enter directly on the first line and then delete it. Here, the background can be basically accessed.

1. At the time of logging in, I was through the external JS file to send Ajax request verification, JS and thinkphp module function communication encountered some problems, has not known the correct path to write, also did not find relevant information, only a variety of tests, fortunately found a solution, By directly bringing the entry file name to the way

var url= "System.php?m=login&a=dolog";  $.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) {   if (data= = "Codeerr") {    alert ("CAPTCHA Error! ");   } else if (data== "Authempty") {    alert ("Please enter your username or password!) ")   }else if (data==" Autherr ") {    alert (" Username or password Error! ");   } else if (data== "Success") {    alert ("Login successful! ");    Location.href= "System.php?m=index&a=index"; Visit Home   }

Of course, this is the normal mode of access, if it is pathinfo, only need to change the red part as follows

var url= "Dolog";  $.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) {   if (data = = "Codeerr") {     alert ("CAPTCHA Error! ");   } else if (data== "Authempty") {     alert ("Please enter your username or password!) ")   }else if (data==" Autherr ") {     alert (" Username or password Error! ");   } else if (data== "Success") {     alert ("Login successful! ");     Location.href= ". /index/index "; Jump Home, Access other modules method

2. Download the file, always inexplicable many HTML things, because the buffer is not empty, can be modified by the following code, but this way is actually downloaded is still HTML file, but changed the suffix named xls, So when you open with Excel will prompt the format problem, ignore can. Also note that you use the Icov () function to convert the encoding because the XLS default encoding format is not utf-8.

Ob_start (); Ob_end_clean (); Header ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"); Header ("content-type:application/vnd.ms-excel;charset=gb2312");  Header ("content-disposition:attachment;filename={$filename}.xls");

3. The path problem is encountered when deleting a file, because the project uses more relative paths, that is, relative to the portal file, but deleting the file requires an absolute path, I did not find a suitable solution, I have to use a more conservative way

$path = "./public/uploads/";      $path =str_replace ("<a target=" _blank "href=" file:///"style=" Color:rgb (51,119,170); Text-decoration:none ">\\ ","/", Realpath ($path)." /</a> ");  Get the absolute path and convert the delimiter

4. In the configuration of Nginx and PHP, I used the fastcgi way, the following code is saved as a CMD file, directly click to run it.
"F:\php\php-cgi.exe"-B 127.0.0.1:9000-c "F:\php\php.ini"//followed by the path of the PHP file
Then add a few words to the Nginx configuration file.

Location ~ \.php/?. * {    root   myapplications;    Fastcgi_pass 127.0.0.1:9000;     Fastcgi_index index.php;     Fastcgi_param script_filename $document _root$fastcgi_script_name;    Include  Fastcgi_params;    #定义变量 $path _info for storing pathinfo information     set $path _info "";     #定义变量 $real _script_name for storing the real address     set $real _script_name $fastcgi _script_name;     #如果地址与引号内的正则表达式匹配     if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") {       #将文件地址赋值给变量 $real _script_name       Set $real _script_name $;       #将文件地址后的参数赋值给变量 $path _info       set $path _info;     }     #配置fastcgi的一些参数     fastcgi_param script_filename $document _root$real_script_name;     Fastcgi_param script_name $real _script_name;     Fastcgi_param path_info $path _info;    }

Related recommendations:

PHP pathinfo () function get file path Information Usage Summary

Parse URL instance using PHP pathinfo (), Parse_url (), basename () function

The [PHP] command line performs a consolidated pathinfo simulation of timed tasks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.