PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to set up an env variable in PHP?

 August 18, 2022     environment-variables, php     No comments   

Issue

I'm trying to set up a enviroment variable in my website.

The idea is to creat a $env='test'; or $env='production'; and all the other PHP files, check this var to see in which env they are.

The solution that I will work now is creating a session in the index file. But I dont feel confortable with this solution.


Solution

The best way to do it is to set your environnements variables inside your... environnement.

If you use Apache, you can add this inside your virtual host configuration (or .htaccess):

SetEnv MYAPP_ENV value

Then, inside your PHP:

$_SERVER['MYAPP_ENV']

There is SetEnv equivalent for all the web servers you can find.



Answered By - Damien
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing