I am developing a internal website and it has no domain (DNS not configured for domain name) so it is just accessed via internal IP address.
I have read that it is a good idea to keep backend files such as php files that connect with the database out of the documentroot and put it one level above. My structure is currently something like this:
/Website Main Directory
/Backend (contains header.php, footer.php, login.php, logout.php)
/Public (index.php, *.css, *.js, *.images)
Apache Virtual host directory points to this Public
folder.
My index.php has include header.php and footer.php which works good and all the files in the public folder works as supposed to.
In my header I have a login form which calls login.php but the problem is login.php is located in the backend. Html can't do what php does which read's the backend files, so it will just throw me a 404. How can I make the html access the login.php in backend folder which is out of the documentroot folder.
Update:
I have tried to include the whole backend folder path but it still says login.php was not found when I submit my form:
<header>
<div class="headerblackbar">
<?php
session_start();
include '/var/www/html/.../.../login.php';
if (isset($_SESSION['loggeduser'])) {
?>
<div class="Loggedin">
<div class="uname">
<?php echo $_SESSION['loggeduser']; ?>
</div>
<form action="logout.php" method="post">
<div class="logoutbtn">
<button class="logoutbtnc" name="logout-submit" type="submit" id="logout-submit">Logout</button>
</div>
</form>
</div>
<?php
} else {
?>
<div class="loginform">
<form action="login.php" method="post">
<div class="uname">
<input placeholder="Username" name="username" id="username" type="text" style="float: left;" required>
</div>
<div class="pwd">
<input placeholder="Password" name="password" id="password" type="password" style="float: right;" required>
</div>
<div class="loginbtn">
<button class="loginbtnc" name="login-submit" type="submit" id="login-submit">Login</button>
</div>
</form>
</div>
<?php
}
?>
</div>
</header>
switch ($_GET["action"]) { case "login": include "../login.php"; break }