Link to home
Start Free TrialLog in
Avatar of czechmate1976
czechmate1976Flag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP: Web path

Can anyone please try to explain to me why one and the same thing is working on my local machine and not on my hosted machine

using this to get the WEB ROOT on the hosted machine:

defined('WEB_ROOT') ? null : define('WEB_ROOT', str_replace(array($docRoot, 'library/initialize.inc.php'), 'public_html', $thisFile))

Result:
web root:  /home/photogr1/public_html    //This is the public_html into which to place displayable files but it shows the whole absolute path - Wrong

This on my local machine:

defined('WEB_ROOT') ? null : define('WEB_ROOT', str_replace(array($docRoot, 'library/initialize.inc.php'), '', $thisFile));

Result:

web root: /PHOTOGRAPHERSCONNECT.com/    //this is a root folder in htdocs for this site - correct

Thanks a lot for your patience and support!!
Avatar of czechmate1976
czechmate1976
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

http://www.photographersconnect.com/home/photogr1/public_html/article/

The link above should look as follows:

http://www.photographersconnect.com/article/

I promise it was all fine on my local machine.. but I am burned spending too much time on this and miss a lot of obvious errors... Thanks for everyones help
SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Elvin. I thought about this before. I have them all in folders by subject and named index, there is actually only one main file in each folder... so this would work but I'd have to go and rewrite all the links in all scripts, if I only change the definition of the web root so it works correctly as when on my local machine, I can avoid re-writing all the links or references- and there are many :-)

what's more, how do I then refer to the one directly in the public folder i.e www.site.com/  ?

Really any advice much appreciated, even a two cent worth one :-)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is how it is set exactly -

$docRoot = $_SERVER['DOCUMENT_ROOT'];

the only difference between the folder setup on my machine and the host server is that the public folder (web root) on my machine was 'htdocs' into which I placed the folder with my site (photographersconnect.com) and the public pages were placed in folder 'public'. Something like
/xampplight/htdocs/PHOTOGRAPHERSCONNECT.COM/PUBLIC

while on the hosted one the public folder is 'public_html'  (=htdocs on my machine), into which I directly placed the files from my PUBLIC folder and everything else was placed outside the public_html in order to disable access to it.

home/photogr1/public_html/(my displayable pages)
home/photogr1/(script library and includes)

displaying the webroot on my machine will show /photographersconnect.com (correct)
but on the server 'home/photogr1/public_html/' none of which should be part of it. It should be like: /index.php or /article/

I don't know where I am going wrong, went through it so many times, echoing it all out but always get the whole absolute path instead of the one leading only to the webroot folder.

Please guys I really appreciate your tips on this This stops me from progressing onto more serious stuff and time is an issue. Thanks a lot to everyone for your input on this
this is what I get echoing it out

docroot: /home/photogr1/public_html
file:         /home/photogr1/library/initialize.inc.php
web root: /home/photogr1/public_html
Through various readings I now realized that my home machine is running on Windows while the hosted server is Unix machine.. would that be the cause of the problem if you look back at my question, the part how the webroot is put together. Thanks a lot
thanks to everyone for participation on my question... I have finally found the solution to my problem.. and it works wonders :-)

Thanks a lot to everyone. The solution is below.
// setting up the web root for this application
$localpath=getenv("SCRIPT_NAME");
$absolutepath=realpath($localPath);
// a fix for Windows slashes
$absolutepath=str_replace("\\","/",$absolutepath);
$docRoot=substr($absolutepath,0,strpos($absolutepath,$localpath));

Open in new window

thanks for your help
Hey I'm glad you got it sorted. It looks like you should have accepted your own answer for this one. This is because of future reference for other people having the same problem. Sure, they will see my answer and think it is the correct one but I believe your solution is the correct one. Mine will work as well but for future reference, I would ask a moderator what they think before accepting an answer if it is not what you are really looking for. I do however appreciate the points!

On another note, I to am a photographer. What is your site about?