0

I have set environment variable in /etc/apache2/envvas

export DATABASE='xyz'
export USERNAME='root'
export PASSWORD='pass'

mode_env is also enable.

I tried with

var_dump($_ENV) but the array contain nothing. how can i access it correctly ?

peterh
  • 11,875
  • 18
  • 85
  • 108
underscore
  • 6,495
  • 6
  • 39
  • 78

2 Answers2

3

You can access env variables through this function:

getenv ( string $varname )

So, if for example you want the database name:

$db = getenv('DATABASE');

Documentation:

http://php.net/manual/en/function.getenv.php

Daan
  • 12,099
  • 6
  • 34
  • 51
0

getenv — Gets the value of an environment variable

Description:-

string getenv ( string $varname )

Gets the value of an environment variable.

See the Manual and you get full clarification . Manual

Examples:-

Example of getenv()

<?php
// Example use of getenv()
$name = getenv($_ENV);

// Or simply use a Superglobal ($_SERVER or $_ENV)
$name = $_SERVER[$_ENV];
?>
RaMeSh
  • 3,330
  • 2
  • 19
  • 31