PHP Web Fundamentals Reading Environment Variables - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Web Fundamentals Reading Environment Variables - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Wednesday, May 29, 2019

PHP Web Fundamentals Reading Environment Variables

PHP Web Fundamentals




Reading Environment Variables

Problem

You want to get the value of an environment variable.

Solution

Use getenv():

           $path = getenv('PATH');

Discussion

Environment variables are named values associated with a process. For instance, in Unix, the value of getenv('HOME') returns the home directory of a user:

           print getenv('HOME'); // user's home directory

PHP automatically loads environment variables into $_ENV by default. However, php.ini development and php.ini-production disables this because of speed considerations.

If you frequently access many environment variables, enable the $_ENV array by adding E to the variables_order configuration directive. Then you can read values from the $_ENV superglobal array. For instance:

          $name = $_ENV['USER'];

The getenv() function isn’t available if you’re running PHP as an ISAPI module.


No comments:

Post a Comment

Post Top Ad