Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that nginx does not support pathinfo in thinkphp

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to solve the problem that nginx does not support pathinfo in thinkphp. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

In fact, there are two ways to solve the problem that nginx does not support pathinfo, one is not to use pathinfo mode, and the other is to modify the configuration file of nginx to make it support pathinfo. In order to simplify the problem, I chose the first way, because in the second way, I checked a lot of information and found that everyone's methods were different, and some of them were very different, which could easily be misleading, so I chose to start from simplicity and choose the ordinary mode. Although there are certain risks. When the foreground code corresponding to index.php is modified, it is found that the foreground is basically normal, but there is still a problem of redirection in the background. After tossing about for a long time, I thought of taking a look at the log file. It turned out that it was the editor's problem. It seemed that the log file was really important and had not been taken seriously before. The output appears on the first line of the config.php file

In sublime, it is common to add BOM headers to UTF-8 files. This BOM header is usually invisible under window and can be looked up through other editors or directly under Linux. It is usually shown as a garbled character, which can be deleted, or simply, enter directly on the first line, and then delete it. At this point, the backstage is basically accessible.

1. When logging in, I sent the Ajax request through the external js file to verify. I encountered some problems in the communication between js and the ThinkPHP module function. I didn't know how to write the correct path, and I didn't find the relevant information. I had to try all kinds of things. Fortunately, I found a solution by directly taking the entry file name.

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 a user name or password!") } else if (data== "autherr") {alert ("wrong username or password!") ;} else if (data== "success") {alert ("login succeeded!") ; location.href= "system.php?m=Index&a=index"; / / visit the home page}

Of course, this is the access method in normal mode. If it is pathinfo, you only need to modify 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 a user name or password!") } else if (data== "autherr") {alert ("wrong username or password!") ;} else if (data== "success") {alert ("login succeeded!") ; location.href= ".. / Index/index"; / / jump to the home page to access other modules

two。 Download files, always inexplicably more than a lot of html things, because the buffer is not empty, can be modified through the following code, but this way is actually downloaded is still the html format of the file, but changed the suffix for xls only, so open with excel will prompt for formatting problems, ignore it. At the same time, you need to be careful to use the icov () function to convert the encoding, because the default encoding format of xls 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. I will encounter the path problem when deleting the file, because the relative path is often used in the project, that is, relative to the entry file, but the absolute path is needed to delete the file. I did not find a suitable solution. I had to use a more conservative way.

The copy code is as follows:

$path= ". / Public/uploads/"

$path=str_replace ("\\", "/", realpath ($path). "/"); / / get the absolute path and convert the delimiter

4. In terms of configuring nginx and php, I use the fastCGI method. Save the following code as a cmd file and click run directly.

"F:\ php\ php-cgi.exe"-b 127.0.0.1 php 9000-c "F:\ php\ php.ini" / / is the path to the php file

Then add a few words to the nginx configuration file

Location ~\ .php /?. * {root myapplications; fastcgi_pass 127.0.0.1 document_root$fastcgi_script_name; include fastcgi_params; 9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; # defines the variable $path_info to store pathinfo information set $path_info "; # defines the variable $real_script_name to store the real address set $real_script_name $fastcgi_script_name # if the address matches the regular expression in quotation marks if ($fastcgi_script_name ~ "^ (. +?\ .php) (/. +) $") {# assign the file address to the variable $real_script_name set $real_script_name $1; # assign the parameter after the file address to the variable $path_info set $path_info $2 } # configure some parameters of fastcgi fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info;} Thank you for reading! This is the end of this article on "how to solve the problem that nginx does not support pathinfo in thinkphp". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report