Jump to content

PHP absolute path to root

Go to solution Solved by Joveice,

I found this way, tho I'm not sure if this is the best way.

<?php

	$path = $_SERVER['DOCUMENT_ROOT'];
	$path .= "/assets/scripts/header_script.php";

	include_once($path);

?>

 

Just now, Mr_KoKa said:

PHP just generates HTML, nothing changes, it is still HTML, so / should work, can you say something more? Do you see your index when accessing / ? or you need to type int "/somedirectory/index.php"?

when I access the /folder/ it displays the index file. tho the php include parts are missing, if I change from /assets to ../assets it displays the index with css

 

Back-end developer, electronics "hacker"

Link to post
Share on other sites

I found this way, tho I'm not sure if this is the best way.

<?php

	$path = $_SERVER['DOCUMENT_ROOT'];
	$path .= "/assets/scripts/header_script.php";

	include_once($path);

?>

 

Back-end developer, electronics "hacker"

Link to post
Share on other sites

Just now, Mr_KoKa said:

I thought you mean links, as you said it worked in HTML, but HTML has no include function, that mislead me a bit.

Oh sorry :) but now as you know what I where looking for. is this a good way to do it?

Back-end developer, electronics "hacker"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×