Home  >  Q&A  >  body text

How to get the root directory of the website in php?

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.000Labmem No.0002528 days ago1156

reply all(2)I'll reply

  • 寻觅 beyond

    寻觅 beyond2017-10-21 12:07:02

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


    reply
    0
  • Labmem No.000

    No, what you get is the project address of the server, not the root directory of the URL.

    Labmem No.000 · 2017-10-21 17:04:33
    寻觅 beyond

    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 · 2017-10-22 10:37:26
  • ringa_lee

    ringa_lee2017-10-21 09:36:43

    PHP has a magic constant __FILE__ that can be obtained

    reply
    0
  • Cancelreply