The idea is to store the base address of the Test Website, which is essentially a subfolder within the main domain (eg: www.mydomain.com/mywebsite/). It is not difficult to get this string value. I just have to use $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']
in the index page.
But what I want is to store this value and use it to include other files. So it doesn't make sense to include a file storing the variable to get the full path. I want to use it as, something similar to $_SESSION["someName"]
. The problem with this is that, for security reasons, I wrapped the session_start()
in a function secure_session_start()
, which is in another file and needs to be included before being called.
So, in short, I need to get the value of this variable before even a single file is included()
or required()
, after it was once set from the 'index.php' page.
If I could use the session_start(), It would have been possible to store in the $_SESSION. But I can't...
EDIT:-
Here's the hierarchy of files:
Now here Public_html points to WWW.MYDOMAIN.COM. That is my website.
I am currently creating a website for my client: WWW.CLIENTWEBSITE.COM. But I'm hosting it only after the website is completed. But for now, the client can see the progress through, WWW.MYDOMAIN.COM/CLIENTWEBSITE/
So when I'm developing the website, I need to either use 'relative paths' (eg: ../somefolder/something.etc) or I can use the 'WWW.MYDOMAIN.COM/CLIENTWEBSITE/' to prefix the url's for include, require, etc. But it will change, once I host it on their domain to WWW.CLIENTWEBSITE.COM. But I don't want to end up changing each and every url's in all the pages. So I want a variable with somewhat a super-global scope which can store this base-url, that I need to change it only once.
I've been experiencing few problems with Relative paths. So, I want to use the full URL to link to a file. That is the reason why I had this question raised.
Problem I'm facing on Relative Paths: (This is not the actual question, but I'm extending it)
index.php
<?php
include_once 'includes/bootstrap_functions.php';
/* ...functions following it... */
bootstrap_functions.php
<?php
include_once "../common/dbhandler.php";
function someDBFunction(){
global $DBH;
.
.
.
/* ...functions following it... */
dbhandler.php
<?php
include_once "psl-config.php";
$DBH = new PDO("mysql:host=".HOSTNAME.";dbname=".DBNAME, DBUSER, DBPASS);
/* ...functions following it... */
psl-config.php
<?php
define("HOSTNAME","localhost");
define("DBNAME","somename");
define("DBUSER","someuser");
define("DBPASS","somepassword");
And then when I run index.php, I get this: