I'm trying to learn HTML and PHP so trying to build a login form with some links.
The bebsite opens OK, however the link to sign up seems to be going nowhere.
My index file as follows:
<?php
include ('../app/header.php');
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Home</h2>
</div>
</section>
<?php
include ('../app/footer.php');
?>
And my header php as follows:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Welcome</title>
<link rel="stylesheet" type="text/css" href="/css/styles.css">
</head>
<body>
<header>
<nav>
<div class="main-wrapper">
<ul>
<li><a href="/index.php">Home</a></li>
</ul>
<div class="nav-login">
<form>
<input type="text" name="uid" placeholder="Username\e-mail">
<input type="password" name="pwd" placeholder="password">
<button type="submit" name="submit">Login</button>
</form>
<a href="../app/signup.php">Sign up</a>
</div>
</div>
</nav>
</header>
The issue is that href
link to signup php takes me nowhere. However if I copy the files into public directory and change the path in the link it then works fine.
Also, after clicking signup link, my URL shows localhost\app\signup.php.
Im using xammp.
Could someone advise as to why the link does not work as expected?
Thanks
UPDATED:
My directory is as follows:
C:\xampp\htdocs\basicwebsite\public\index.php
and all PHP files are here:
C:\xampp\htdocs\basicwebsite\app
For what I understood so far these are your folders:
// site
// app
signup.php
// public
index.php
Your http server is using the public
folder as doc root, therefore accessing http://localhost/index.php
is the same as public/index.php
.
If you link to ../app/signup.php
your browser will attempt to access http://localhost/../app/signup.php
, since you can't request files outside your doc root it will not find your file.
That's not exclusive to php, apache or even xampp but is true for all http servers.
For it to work, all your system's entry points (like index and signup) must be made public for the browsers.
Moving your file to public/signup.php
and updating the link will work.