Brian Antiqueña
Brian Antiqueña

Reputation: 188

How to know the root of your website using $_SERVER?

for example is I have a example site in xampp localhost htdocs:

C:/xampp/htdocs/example

and when I view the $_SERVER['PHP_SELF'] in a specific .php inside the sub-folder of the root, I will have to use the first string to get the root: specific .php inside the subfolder:

C:/xampp/htdocs/example/subfolder/page.php

$_SERVER['PHP_SELF'] I will get in the .php:

/example/subfolder/page.php 

but when I try this in a free hosting site, I get this:

/subfolder/page.php

the root I need in the localhost is:

/example/

while in a hosting site is:

/

is there a code to get the root of your website for both localhost and in a hosting site? or is there a hint/flag whatev. it is if I will need to use the first string /*first_string*/ to get the root in the $_SERVER? thanks!

Upvotes: 0

Views: 66

Answers (1)

Alex Angelico
Alex Angelico

Reputation: 4065

$_SERVER['DOCUMENT_ROOT']

adding more characters to be able to save the answer....

Upvotes: 1

Related Questions