php获取当前URL的相关代码
<?php echo $_SERVER['SERVER_NAME']?> localhost80
<?php echo $_SERVER["SERVER_PORT"]?> manager/products/
<?php echo $_SERVER["REQUEST_URI"]?> product.php
URL: http : / / www.baidu.com/product/index.php
$_SERVER['HTTP_HOST']=='www .baidu .com' 一个是主机地址
$_SERVER['PHP_SELF']=='/product/index.php' 一个是脚本文件的绝对路径
/**/
获取跳转前的URL
$_SERVER ['HTTP_REFERER']
分类 "PHP" 下的文章
问题:网站在本地windows系统apache服务器正常,上传到linux系统nginx服务器之后报404错误,thinkphp在linux访问页面打不开,报 404错误
解决:如果发生在本地测试正常,但是一旦部署到服务器环境后会发生只能访问首页的情况,很有可能是你的服务器或者空间不支持PATH_INFO所致。
方法:下面是thinkphp在nginx下nginx的配置方法
server {
listen 80;
server_name www.zhtuu.com zhtuu.com;
index index.html index.htm index.php;
root /alidata/www/default;
location / {
try_files $uri @rewrite;
}
location @rewrite {
set $static 0;
if ($uri ~ .(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css.map|min.map)$) {
set $static 1;
}
if ($static = 0) {
rewrite ^/(.*)$ /index.php?s=/$1;
}
}
问题:搭建的thinkphp网站,只有首页能显示,其余都是404错误
解决:nginx配置错误
方法:
sudo vi /etc/nginx/sites-available/default
找到下面的代码
#location ~ .php$ {
# fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
#}
问题:typecho分类列表,如何对当前分类增加active样式?
解决:使用$categorys->slug
方法:
<ul class="navbar-nav mr-auto">
<li class="nav-item<?php if($this->is('index')):?> current<?php endif;?>">
<a class="nav-link" href="<?php $this->options->siteUrl(); ?>">
<span><?php _e('首页'); ?></span></a>
</li>
<?php $this->widget('Widget_Metas_Category_List')->to($categorys); ?>