Reputation: 399
I am building a PHP mySQL site locally with WAMP.
in my WAMP www directory i have made subfolders for each website I am making. eg:
WAMP\www\site1\index.php
WAMP\www\site2\index.php
WAMP\www\site3\index.php
etc
my DB connection is stored in:
site1/connections/open.php
my PHP scripts are stored under:
site1/php/filename.php
when i am running a script i need to include the open.php connection. the only way i can get this to work is by using:
include '../connections/open.php'; // this goes at the top of the PHP script
I know that if i use this and then move to remote servers or move some directories around I will have problems accessing this file. I therefore want the path to be relative to the basedir or baseurl(/site1/).
I understand that when you use an include it is looking for a dir and not an url so I cant use anything like;
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
How do you go about sorting this out? Thanks
Upvotes: 1
Views: 1554
Reputation: 73
Yes you are right on that URL part
I understand that when you use an include it is looking for a dir and not an url so I cant use anything like;
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
How do you go about sorting this out? Thanks
You should try like this
$_SERVER["DOCUMENT_ROOT"]."/myFolder/"
Or try this
getcwd()."/myFolder/"
But there is a difference between both of them [Try Googling]
Upvotes: 1
Reputation: 7175
I think when you move to remote servers or move some directories around you will have no problems,because you are using relative path. I think you should not use "$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']" and I think you should know what they mean!
Upvotes: 0