我们要区分不同的环境,php中很多人设置在$_SERVER中,比如ci(coderigniter)
define(‘ENVIRONMENT’, isset($_SERVER[‘CI_ENV’]) ? $_SERVER[‘CI_ENV’] : ‘development’);
这个ci_env就是我们自己定义的。通常我们会定义在apache或者nginx中。
打开一个nginx的网站配置,在location中加入你想要加的变量:
location ~ \.php$ {
try_files $uri =404;
root /usr/share/nginx/html/tanteng.me/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MYENV 'DEV'; #这个就是你要加的变量
include fastcgi_params;
}
这里的fastcgi_param MYENV ‘DEV’,就是新加的一行语句。
在PHP中打印$_SERVER看看:
array (size=33)
'USER' => string 'apache' (length=6)
'HOME' => string '/usr/share/httpd' (length=16)
'HTTP_ACCEPT_LANGUAGE' => string 'zh-CN,zh;q=0.9' (length=14)
'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)
'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' (length=85)
'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' (length=114)
'HTTP_UPGRADE_INSECURE_REQUESTS' => string '1' (length=1)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'HTTP_HOST' => string 'test.com' (length=8)
'REDIRECT_STATUS' => string '200' (length=3)
'SERVER_NAME' => string 'test.dev' (length=8)
'SERVER_PORT' => string '80' (length=2)
'SERVER_ADDR' => string '10.0.2.15' (length=9)
'REMOTE_PORT' => string '53980' (length=5)
'REMOTE_ADDR' => string '10.0.2.2' (length=8)
'SERVER_SOFTWARE' => string 'nginx/1.10.1' (length=12)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'REQUEST_SCHEME' => string 'http' (length=4)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'DOCUMENT_ROOT' => string '/usr/share/nginx/html/test' (length=26)
'DOCUMENT_URI' => string '/index.php' (length=10)
'REQUEST_URI' => string '/' (length=1)
'SCRIPT_NAME' => string '/index.php' (length=10)
'CONTENT_LENGTH' => string '' (length=0)
'CONTENT_TYPE' => string '' (length=0)
'REQUEST_METHOD' => string 'GET' (length=3)
'QUERY_STRING' => string '' (length=0)
'SCRIPT_FILENAME' => string '/usr/share/nginx/html/test/index.php' (length=36)
'MYENV' => string 'DEV' (length=3) #这个就是我们刚加的变量
'FCGI_ROLE' => string 'RESPONDER' (length=9)
'PHP_SELF' => string '/index.php' (length=10)
'REQUEST_TIME_FLOAT' => float 1531473189.9756
'REQUEST_TIME' => int 1531473189
搜索
标签
study
ab
amap
apache
apahe
awk
aws
bat
centos
CFS
chrome
cmd
cnpm
composer
consul
crontab
css
curl
cygwin
devops
di
docker
docker,docker-compose
ethereum
excel
fiddler
fluentd
framework
front-end
git
gitgui
github
glide
go
golang
gorm
grafana
gzip
ioc
item2
iterm2
javascript
jenkins
jsonp
kafka
laradock
laravel
larval
linux
liunux
log
mac
mac, wi-fi
macos
magento
mariaDB
minikube
mongoDB
msp
mysql
netbeans
nginx
nodejs
nohup
npm
nsq
php
php-fpm
php7
phpstorm
php扩展
Protobuf
python
redis
scp
server
shell
soap
socket
socket5
sql
sre
ssdb
ssh
ssl
study
sublime
swift
system
td-agent
uml
v2ray
vagrant
vagrnat
vim
vpn
vue
vue.js
webpack
webrtc
websocket
webtatic
windows
windows7
word
wps
xdebug
yarn
yii2
yum
zookeeper
世界国家
互联网
以太坊
分类
前端
小程序
打印机
排序算法
搞笑
权限
粤语
缓存
网络
虚拟机
视频
设计模式
项目管理
热门文章
友情链接