Getting user environment variables using PHP

给你一囗甜甜゛ 提交于 2019-12-24 18:18:58

问题


On centos and Redhat I created a file /etc/profile.d/marketing_vars.sh and added following lines to it

#Vars  for PowerMail
export CmsRoot="/var/www/html/cms/"
export PMRoot_Dev="/var/www/html/powermail/"
export PMRoot_QA="/var/www/html/powermail/"
export PMRoot_Pro="/var/www/html/powermail/"

On command line i hit "source marketing_vars.sh" and "chmod +x /etc/profile.d/marketing_vars.sh"

I then created a test.php file and added these lines to it

error_reporting(E_ALL ^ E_NOTICE);
echo "PMRoot_Dev = " . getenv("PMRoot_Dev");
echo "<br>";
echo "PMRoot_QA = " . getenv("PMRoot_QA");
echo "<br>";
echo "PMRoot_Pro = " . getenv("PMRoot_Pro");
echo "<br>";

When I browse a test.php I get no value for any of the variable. Can anyone help ?


回答1:


Apache on Centos doesn't include the env variables like you expect. One solution is to include by hand the file inside /etc/sysconfig/httpd.

  • append /etc/profile.d/marketing_vars.sh to the end of /etc/sysconfig/httpd
  • restart apache

The best solution to be consistent in apache, CLI and crons is to use a configuration file and include/parse it to get the variable.



来源:https://stackoverflow.com/questions/17447360/getting-user-environment-variables-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!