[RESOLVED]How to access the Apache `$_SERVER`global variable
Moderator: General Moderators
[RESOLVED]How to access the Apache `$_SERVER`global variable
I am trying to figure a way to query the server's $_SERVER global variable to get access to it's "HOME" property. I do not have root access on my website, it is shared hosting. A reference to the above can be found at: http://php.net/manual/en/reserved.variables.server.php. Thanks in advance for your help.
Last edited by xtianos on Thu May 28, 2015 11:50 pm, edited 2 times in total.
Re: How to access the Apache `$_SERVER`global variable
As far as I know, $_SERVER['HOME'] is available only through the CLI. What is it you're trying to do?
Re: How to access the Apache `$_SERVER`global variable
I am trying to hone my PHP skills before I purchase the Certification book and take the test. Basically, I am writing my own framework (no GUI interface, just code) and in doing so I needed to declare some constants that would automatically define themselves without me having to hard-code anything. At the beginning I followed the concept of "make it work first, then tweak it for efficiency", so I ended up hard-coding CONSTANTS values, but as I went over the code and began making my tweaks I was unable to find a way to set that value automatically. The idea is for me to copy/paste that framework into another ISP and it would automatically set the constants for me without the need of hard-coding.
Re: How to access the Apache `$_SERVER`global variable
I'm not sure where $_SERVER['HOME'] would fit in, then. That literally maps to your home directory; /home/username (or /Users/username on OS X). What if your site lives in /var/www? Maybe defining some constants relative to your bootstrap file, say using dirname(), would make more sense.
Re: How to access the Apache `$_SERVER`global variable
It would be in the "index.php" file in the "public_html" folder and would look something like:
I just want to avoid having to write the full path to define the first constant. Right now I am calling the file that has all the constant definitions with the full path, then after that I begin using CONSTANTS for the remainder of the framework. Currently the constants file is inside the main root folder of the framework, so I am using the __DIR__ to refer to the framework folder. Hope it makes sense.
Code: Select all
define("FRAMEWORK_PATH", $_SERVER["HOME"] . "/framework_folder_name");
require_once FRAMEWORK_PATH . "/Framework.Constants.php";
require_once CONTROLLER_PATH . "/Main.Controller.php";
// Rest of code here...
Re: How to access the Apache `$_SERVER`global variable
What you've described sounds about like how I'd approach it. Use dirname(__FILE__) inside your bootstrap to define the install path then define all other paths relative to that.
Code: Select all
define('BASE_PATH', dirname(__FILE__));
define('APP_PATH', BASE_PATH . '/app');
etc.
[RESOLVED] How to access the Apache `$_SERVER`global variabl
Roger that! I appreciate the time you took to look over my post and reply. Cheers!