我可以在链接中使用魔术常量__DIR__吗?

So, I have a question regarding paths in links. Here's the problem: In my assignment all my links are broken (not all but half of them don't work).

html_start.php includes nav.php and start_html is included in /admin/index.php and so on.

public_html
    html_start
    nav
styles.css 
admin
    index.php
user
    index.php
index.php

First I've tried using absolute path eg. a href = "/user/index.php" but the assistent warned me that it leads to homepage of my university not my index.php. If I use relative links, half of them work do to the includes.

Sadly all of these work in my environment but not when it's uploaded to my school so I don't know how it will behave until I upload the assignment and I have only one attempt to correct it.

Now, i use include in almost every page - eg. include( __DIR__.'/app.cfg.php') and that apparently works. So my question is can I do the same with links? I've read somewhere that it doesn't do the same thing.

Looks like you're working in "root" (localhost?), where absolute links are fine, but when the site gets set up at your school's server, then absolute links point to the school's domain instead of the subdirectory where your project is.

What you need is using <base> tag in combination with relative links. Note that it may mess up your css/js/images, so you'd need to update all paths to be relative (not starting with /). Here's an example:

<html>
  <head>
    <base href="http://example.com/"/>
[...]
<a href="dir/page.html">link</a>

The link above would point to http://example.com/dir/page.html. Basically, setting an URL in base tag sets what is the "root" of your website, and all relative links will respect it. You can store the value of base in your site's config and echo it in the template, so when your site is set up on another server you'd update the config file and all links/images/css/etc would work.