2022年12月

/**
 * 几秒几天前,时间转换
 * @return string
 */
if (!function_exists('format_time_ago')) {
    function format_time_ago($date)
    {
        if(is_numeric($date)){
            $timer = $date;
        }else{
            $timer = strtotime($date);
        }
        $diff = $_SERVER['REQUEST_TIME'] - $timer;
        $day = floor($diff / 86400);
        $free = $diff % 86400;
        if ($day > 0) {
            return $day . "天前";
        } else {
            if ($free > 0) {
                $hour = floor($free / 3600);
                $free = $free % 3600;
                if ($hour > 0) {
                    return $hour . "小时前";
                } else {
                    if ($free > 0) {
                        $min = floor($free / 60);
                        $free = $free % 60;
                        if ($min > 0) {
                            return $min . "分钟前";
                        } else {
                            if ($free > 0) {
                                return $free . "秒前";
                            } else {
                                return '刚刚';
                            }
                        }
                    } else {
                        return '刚刚';
                    }
                }
            } else {
                return '刚刚';
            }
        }
    }
}

定义前:
http://doamin/index.index/index
http://doamin/admin.index/index

Route::rule(':version/:controller/:action',':version.:controller/:action');

定义后:
http://doamin/index/index/index
http://doamin/admin/index/index

#   指定允许跨域的方法,*代表所有
    add_header Access-Control-Allow-Methods *;

    #   预检命令的缓存,如果不缓存每次会发送两次请求
    add_header Access-Control-Max-Age 3600;
    #   不带cookie请求,并设置为false
    add_header Access-Control-Allow-Credentials false;

    #   表示允许这个域跨域调用(客户端发送请求的域名和端口) 
    #   $http_origin动态获取请求客户端请求的域   不用*的原因是带cookie的请求不支持*号
    add_header Access-Control-Allow-Origin $http_origin;

    #   表示请求头的字段 动态获取
    add_header Access-Control-Allow-Headers 
    $http_access_control_request_headers;

    #   OPTIONS预检命令,预检命令通过时才发送请求
    #   检查请求的类型是不是预检命令
    if ($request_method = OPTIONS){
        return 200;
    }

phpstudy nginx设置cors跨域不起作用的可能解决方法

location / {
    #...
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods *;
    add_header Access-Control-Allow-Headers *;
}

1.注意事项

服务器web服务必须是nginx,apache暂未做适配,php必须以php-fpm启动,即LNMP才支持,LNAMP和LAMP不支持。

服务器同时安装了php5.6和php7.1,php5.6和php7.1已经同时启动。

2.开始配置

修改nginx配置文件

宝塔站点管理点击您想配置的站点,选择配置文件,我们先将33行左右的include enable-php-xx.conf前加#注释掉然后加入如下代码

location ~ [^/]\.php(/|$)

    {    

        fastcgi_pass unix:/tmp/php-cgi-71.sock; 

        fastcgi_index index.php;

        include fastcgi.conf;

        include pathinfo.conf;

        if ($request_uri ~* "ndot_ladderbuy"){   

            fastcgi_pass unix:/tmp/php-cgi-72.sock;    

        }   

    }