在 .htaccess 中设置环境变量并在 PHP 中检索它 [英] Set an environment variable in .htaccess and retrieve it in PHP

查看:24
本文介绍了在 .htaccess 中设置环境变量并在 PHP 中检索它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 .htaccess 文件中设置环境变量并在 PHP 中检索它.我已经在 SO 上浏览了许多其他主题,但到目前为止我尝试过的一切都失败了.

I am trying to set an environment variable in an .htaccess file and retrieve it in PHP. I've looked through a bunch of other threads here on SO but everything I've tried so far has failed.

我已将此行添加到 .htaccess 文件中:

I've added this line to the .htaccess file:

SetEnv SPECIAL_PATH /foo/bin

我尝试使用 getenv() PHP 函数检索此值:

I have tried retrieving this value using the getenv() PHP function:

<?php $specialPath = getenv('SPECIAL_PATH'); ?>

我已经运行 phpinfo() 来查看可用环境变量的列表,但 SPECIAL_PATH 不存在.我很困惑为什么这不起作用.

I have runned phpinfo() to see the list of available environment variables, SPECIAL_PATH is not there. I am puzzled as to why this is not working.

谢谢!

推荐答案

假设您的配置具有带 .htaccess 的 AllowOverrides,您必须在 Apache 中启用 mod_env 才能使其工作.

Assuming your configuration has AllowOverrides with .htaccess, you must enable mod_env in Apache for this to work.

Apache - mod_env

这篇关于在 .htaccess 中设置环境变量并在 PHP 中检索它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆