R.Shamon
R.Shamon

Reputation: 43

Isses with __DIR__ PHP code implementing the wrong home directory

My home directory path is /home9/ but when I using the __DIR__ code to get the path, I get /home/ it's missing the number 9, I know I can get the path by using $_SERVER['DOCUMENT_ROOT'], I just want to know why and how to fix it, I really need to use the __DIR__ code.

<?php
// this is the first code
echo __DIR__ .'<br>'; //I get /home/username/public_html/ is the wrog path

// this the secound code
echo $_SERVER['DOCUMENT_ROOT']; //I get /home9/username/public_html/ the correct path
?>

I contacted my hosting provider and they couldn't help, please help.

Upvotes: 1

Views: 223

Answers (1)

Pasan Chamikara
Pasan Chamikara

Reputation: 755

These are 2 different things.

Here in your case /home9/username/public_html/ is symlinked to /home/username/public_html/ where /home9/username/public_html/ is the actual document root. However __DIR__ returns the real path where symlink resolves to.

You can refer php documentation for more information in between these 2.

Upvotes: 1

Related Questions