What Can Access “App Settings Key Values”?

為{幸葍}努か 提交于 2020-05-02 02:01:10

问题


In an Microsoft Azure Web App Service under Application Settings, there are Key-Value pair options within the option App Settings. If a developer has PHP or Python files in multiple directories, which of these directories and (or) files would have access to these key-value pairs.

Example:

Suppose the developer has the following key value pair settings in App Settings:

Key: $variableString | Value: "My first example string."

Key: $variableNumber | Value: 1000

PHP files:

site\wwwroot\index.php

site\wwwroot\folderone\pageone.php

site\wwwroot\folderone\pagetwo.php

site\wwwroot\foldertwo\page.php

Would all these files have access to these variables, or would these files need to have a reference (and where?) to where these key-value pairs would be saved like in each PHP file with an include pointer to the App Settings file (Azure doesn't show this becomes a file)?

Thanks.


回答1:


They will be available as environment variables so it doesn't matter where the file is.

If you set an app setting with key ITEM_COUNT and value 15, you could use:

$item_count = getenv('ITEM_COUNT');

Or:

$item_count = getenv('APPSETTING_ITEM_COUNT');

And $item_count would contain the string "15".




回答2:


Anything that can access environment variables can access those, as those are environment variables. So python would be able, not sure about php, since I know nothing about it, but pretty sure it could.

In my code I just use this:

"{0}-{1}".format(os.getenv('LOCATION'), os.getenv('COMPUTERNAME'))



来源:https://stackoverflow.com/questions/40531496/what-can-access-app-settings-key-values

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