How to get the root directory of the website in php?
Labmem No.000
Labmem No.000 2017-10-21 00:49:18
0
2
1198

I originally learned java by using <%=request.getContextPath()%> to get the site root directory, but now I’m confused when learning php

java is

< ;a href="<%=request.getContextPath()%>/html/main/main.jsp">Homepage</a></span>

How to write php

Labmem No.000
Labmem No.000

reply all(2)
寻觅 beyond

You can use $_SERVER['DOCUMENT_ROOT'] to get


  • reply No, what you get is the project address of the server, not the root directory of the URL.
    Labmem No.000 author 2017-10-21 17:04:33
  • reply Reply to Labmem No.000: Then you can just use $_SERVER['HTTP_HOST'] to obtain the domain name. The domain name is the root directory of the site.
    寻觅 beyond author 2017-10-22 10:37:26
ringa_lee

PHP has a magic constant __FILE__ that can be obtained

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template