So im quiet new to coding in general and i started making a shop page where everything is dynamiclly put throught databases . Now the thing is that for example i have created index.php file where user would directly go to and from there he can choose his next category or whatever hes looking for.
Now the issue is that if someone does like index.php/asfjasflk , the index page will render and there’s missing photos / links and so on , so the thing is how to prevent that from happening even if they input something to re direct them to main website or where they are.
To show you more what im talking about.
Index normally index when someone puts something
I have a free host because i wanted to test the .htaccess file as ive seen around but it seems not working , yes i have set Rewrite to on , i set 404 page custom but it still recognizes the default one or doesnt recognize it at all .
http://agcomputers.onlinewebshop.net/index.php – this is the main file and if you do http://agcomputers.onlinewebshop.net/index.php/asfkjasfklajsfas – You still get the main file but its empty and the url is re writen if i click on other links.
Here’s the loginPage code.
Note: This happens with all the pages / files in my folder/website.
require_once("../includes/db.php");
require_once("../includes/sessions.php");
require_once("../includes/functions.php");
?>
<?php
if(isset($_SESSION['User_ID']))
{
Redirect_to("dashboard.php");
}
if(isset($_POST['submit']))
{
$adminUser = $_POST['username'];
$adminPassword = $_POST['password'];
if(empty($adminUser) || empty($adminPassword))
{
$_SESSION['ErrorMessage'] = "Emri ose Passwordi eshte bosh";
Redirect_to("login.php");
}
else
{
if(CheckUsernameExistsOrNot($adminUser) == true)
{
$found_account = LoginAttempt($adminUser, $adminPassword);
if($found_account)
{
if(password_verify($adminPassword, $found_account['password']))
{
$_SESSION['User_ID'] = $found_account['id'];
$adminUser = $_SESSION['adminName'] = $found_account['adminName'];
$_SESSION['SuccessMessage'] = "Welcome $adminUser";
if(isset($_SESSION['TrackingURL']))
{
Redirect_to($_SESSION['TrackingURL']);
}
else
{
Redirect_to("dashboard.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Passwordi nuk eshte i sakt";
Redirect_to("login.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Username ose Passwordi eshte gabim";
Redirect_to("login.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Username nuk ekziston ne databaze";
Redirect_to("login.php");
}
}
}
?>`
`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/styles.css">
<script src="https://kit.fontawesome.com/496fd68b03.js" crossorigin="anonymous"></script>
<title>AG Computers</title>
</head>
<body>
<!-- SideBar Start -->
<div class="main-container d-flex">
<div class="content">
<!-- Dashboard Content -->
<div class="dashboard-content px-3 pt-4">
<div class="container container-fluid">
<div class="row ">
<div class="offset-1 col-lg-8 " >
<div class="card login-form mt-2 mb-2 p-4" style="top: 90%; ">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form action="login.php" method="post">
<div class="card-header">
<h3 class="text-white">Login</h3>
</div>
<label class="text-white" for="username">Username:</label>
<input type="text" id="username" name="username" class="form-control">
<label for="password" class="text-white mt-2">Password:</label>
<input type="password" id="password" name="password" class="form-control ">
<button class="btn btn-outline-info text-black form-control mt-2" type="submit" name="submit">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div><!-- Content Div -->
</div> <!-- Main Flex Container Div -->
<!-- FOOTER -->
<footer class="text-white" style="background-color: #000;">
<div class="container ">
<div class="row d-none d-md-block">
<p class="lead text-center">Theme by <span id="year"></span></span> © --- All Rights Reserved</p>
</div>
</div>
</footer>
<!-- End FOOTER -->
<!-- Dashboard Content End -->
<!-- SideBar End -->`
`<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript">
$('.sidebar ul li').on('click', function(){
$('.sidebar ul li.active').removeClass('active');
$(this).addClass('active');
});
$('.open-btn').on('click', function(){
$('.sidebar').addClass('active');
});
$('.close-btn').on('click', function(){
$('.sidebar').removeClass('active');
});
</script>
</body>
</html>``
I tried to put up .htaccess and that did not work aswell
2
Answers
You are currently calling the CSS via this code :
You should change the link from relative path (href="css/styles.css")
To absolute Path (href="/css/styles.css" , or something similar depending on how your folders are organised)
otherwise, when adding a slash at the end of the URL, your code will try to get the CSS from http://agcomputers.onlinewebshop.net/index.php/styles.css, when it should be http://agcomputers.onlinewebshop.net/styles.css (again, could be different depending on how you organised your folders)
hope it helps
Edit : mistyped ./ instead of / before absolute path
Second Edit : just double checked and it seems the CSS is not the only problem, you are also calling the folders "images" and "uploads" via relative paths, which should be changed as well.
example of a wrong call of the uploads folder
uploads relative path call
Simply Put this Redirect in your Page if Someone visit it with extra Params it will redirect to vase file.