PHP provides variable which gives some information about the environment in which PHP is running.
On windows to get these Environment varibale populated you must set the PHP path in the environment variable.
So if you have not set this path properly then your PHP might not run. In my case all php code was displaying in browser same as we can see the text file in browser.
We can get these variables from $_SERVER and $_ENV arrays. These two arrays are the PHP superglobal array and can be accessed from any where.
1) Go to control panel >> System >> Advance System Settings
2) You will get one window as per below image. Click on the Environment Variable button.
3) From the System variable section, scroll down for the variable “Path”, select it and edit.
4) Add (at the end) your path to the PHP folder starting with ; , (like ;c:/PHP)
5) Save environment variable box and restart Apache.
After setting up the Environment Variable path, PHP will able to populate the $_SERVER and $_ENV arrays.
Environment varibales can be accessed via $_SERVER and $_ENV supergloabal arrays. Please see these are super globals so you do not need to declare them as a global.
This code block will show how to set the custom environment varibale.
Note: Above variable will be available for particular session only.
Below code is used to set the Environment Variable using .htaccess file.
Note: Using SetEnv, variable name must start with HTTP_ for the securiry reasons.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash