php - Where is Doc Root -


when run code on localhost

$root = $_server['document_root']; echo "doc root : $root <br />"; 

it responds with:

doc root : c:/wamp/public_html/  

when run same code on remote server responds with:

doc root : /home/setine5/public_html 

notice not have trailing "/"

i'm trying find way reference same piece of php on both localhost , remote server cannot because of missing forward slash.

how done normally?

you can not in advance if $_server['document_root'] contains slash @ end or not. varies according environment. in cases, doesn't have trailing /, in windows, trailing slash cause issues.

the solution here, dave suggested, append trailing slash if doesn't exist.

$_server['document_root'] = sprintf('%s/', rtrim($_server['document_root'], '/')); 

an alternative solution:

$_server['document_root'] .= (substr($_server['document_root'], -1) == '/')?'':'/'; 

hope helps!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -