The previous time with the Apache with TP developed a small website, also is I use TP the first combat. I am accustomed to use PathInfo mode, the local run everything is normal, but deployed to the server, because the other side is using Nginx, the default is not support thinkphp PathInfo mode, so lead to path error, there is a page loop jump problem, So I downloaded Nginx to the local test.
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.
There are a few small questions to explain.
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, the code is as follows
Copy the Code code as follows:
var url= "System.php?m=login&a=dolog";
$.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) {
if (data== "Codeerr") {
Alert ("The verification code is wrong! ");
}else if (data== "Authempty") {
Alert ("Please enter your username or password!") ")
}else if (data== "Autherr") {
Alert ("The user name or password is wrong!") ");
}else if (data== "success") {
Alert ("Login successful! ");
Location.href= "System.php?m=index&a=index"; Visit homepage
}
Of course, this is the normal mode of access, if it is pathinfo, only need to change the red part as follows
Copy the Code code as follows:
var url= "Dolog";
$.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) {
if (data== "Codeerr") {
Alert ("The verification code is wrong! ");
}else if (data== "Authempty") {
Alert ("Please enter your username or password!") ")
}else if (data== "Autherr") {
Alert ("The user name or password is wrong!") ");
}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.
Copy the Code code as follows:
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 is used more relative path, that is relative to the portal file, but delete the file need to use absolute path, I did not find the appropriate solution, I have to use a more conservative way, the code is as follows
Copy the Code code as follows:
$path = "./public/uploads/";
$path =str_replace ("\ \", "/", Realpath ($path). " /"); 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.
Copy the Code code as follows:
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 real addresses
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;
}