Boon Boon - 10 months ago 40
PHP Question


if( isset( $_SESSION['username'] ) ){
$username = $_SESSION['username'];
$welcomeMessage = "Hello $username! | ";
$welcomeMessage .= '<a href="'.$_SERVER['DOCUMENT_ROOT'].'/nmc/Admin/LogoutProcessor.php">Logout</a>';
} else {
$welcomeMessage = "Welcome | ";
$welcomeMessage .= '<a href="'.$_SERVER['DOCUMENT_ROOT'].'/nmc/Admin/LoginPage.php">Login</a>';

The code above returns "file:///C:/xampp/htdocs/nmc/Admin/LoginPage.php"

I am using xampp to develop a website, basically uses its own server processing, therefore I can't use the above link. I have several webpages in different directories which have to link to the LoginPage.php, and I need a standard link. The above code is in a Class where other pages in different directories can call it.

Can anyone tell me how to resolve this problem?




The document root directory under which the current script is executing, as defined in the server's configuration file.

You could use $_SERVER['HTTP_HOST'] or absolute paths like <a href="/nmc/Admin/LoginPage.php">Login</a>