mrkirby153
mrkirby153

Reputation: 85

PHP Get root directory of website

I am making a site and I need to get the "root" directory of the site. Like if the filestructure was similar to

CloudShop
    \-internal
        \-js
            ...
        \-inc
            inc.all.php
    index.php
    \-login
        login.php
        loginError.php
    page.php

In inc.all.php I am getting all the pages in the database so I can display them in the navigation bar and I am setting the links like <a href="page.php?id=XXX>PAGE_TITLE</a> However, when I click on one of the page links from login.php, it takes me to /CloudShop/login/page.php?id=XXX. I want it to take me to /CloudShop/page.php?id=XXX.

Upvotes: 1

Views: 331

Answers (2)

Metablocks Corp
Metablocks Corp

Reputation: 1665

Suggestion: Try the PHP Magic constants:

__DIR__ 

Upvotes: 0

icktoofay
icktoofay

Reputation: 129119

You can use path-absolute URIs. Suppose you had at http://www.example.com/shop/login/login.php:

<a href="/shop/page.php?id=1">page</a>

The resolved URI would be http://www.example.com/shop/page.php?id=1.

Upvotes: 2

Related Questions