自定义添加$_SERVER中的变量

如何根据自己项目中的需求自定义$_SERVER中的变量呢?比如$_SERVER['XU_TEXT_PARAM'],这个超全局变量输出肯定是会报错的。那如何自定义它,让它输出我们想要输出的值呢?

1、在apache服务器下:

<VirtualHost *:80>
#放在里面则只有当前站点可以访问到,如果想要所有站点都访问到就放在外面
SetEnv XU_TEXT_PARAM 'this is a demo'  
 #配置一个域名 ServerName
    
ServerName  xu-test.com
#配置域名对应的目录
    
DocumentRoot  "D:\project\test"
    
#配置访问的权限
    
<Directory "D:\project\test">
     
#允许所有用户访问
     
Require all granted
       
 AllowOverride All
     
#配置一个默认的页面
     
DirectoryIndex index.php
    
 #如果没有默认显示的页面就把所有文件以列表的形式显示出来
    
 Options Indexes followsymlinks execcgi

    
</Directory>


</VirtualHost>

  2、在nginx服务器下。

server {
        listen       80;
        server_name  a.com;
        root   "D:\phpStudy\PHPTutorial\WWW\a.net";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;   #可以放到一个共用文件里面 需要的项目则包含
            fastcgi_param  XU_TEXT_PARAM  'test';#只针对当前项目 会覆盖fastcgi_params中的值
        
原文:https://blog.csdn.net/slyjit/article/details/85243865 

 

 

posted @ 2019-07-19 10:27  yunhenX  阅读(944)  评论(0编辑  收藏  举报