Compare commits

...

7 Commits

21 changed files with 642 additions and 2 deletions

6
.htaccess Normal file
View File

@@ -0,0 +1,6 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?page=$1 [QSA,L]

164
README.md
View File

@@ -1,3 +1,163 @@
# sld-php-template # SLD PHP Template
Basic php framework for php plain websites. A lightweight and modular PHP starter framework for building plain PHP websites without heavy dependencies.
This project is designed to provide a clean structure, reusable components, and a simple initialization system to speed up development while keeping full control over the codebase.
---
## 🚀 Features
- ⚡ Lightweight and fast (no external frameworks required)
- 📁 Clean and scalable folder structure
- 🔧 Centralized configuration system
- 🧩 Modular templates (header, footer, includes)
- 🎨 Basic frontend setup (CSS variables, animations, JS helpers)
- 🛠 Ready-to-use initialization system
- ❌ Built-in error pages (environment & database)
---
## 📂 Project Structure
```
.
├── admin/
├── assets/
│ ├── css/
│ ├── img/
│ └── js/
├── config/
├── functions/
├── includes/
├── pages/
├── templates/
├── themes/
├── public/
├── index.php
└── README.md
```
---
## ⚙️ Configuration
All core configuration is located inside the `config/` directory:
- `init.php` → Application bootstrap
- `constants.php` → Global constants
- `settings.php` → App settings
- `db.php` → Database connection
- `functions_init.php` → Function loader
---
## 🧠 How It Works
1. The application starts from `index.php`
2. Core initialization is handled by the config system
3. Templates are loaded dynamically (`header.php`, `footer.php`)
4. Pages are rendered from the `pages/` directory
5. Custom logic can be added via the `functions/` folder
---
## 🎨 Frontend
The project includes a minimal frontend setup:
### CSS System
- Variables-based color system with multiple shades
- Basic layout styles
- Animation utilities
### JavaScript
- Simple helper functions like dynamic year rendering
---
## 🛠 Usage
1. Clone the repository:
```bash
git clone https://github.com/your-username/sld-php-template.git
```
2. Move it into your web server directory
3. Configure:
- Database (`config/db.php`)
- Environment settings (`config/settings.php`)
4. Open in browser:
```
http://localhost/your-project
```
---
## 📄 Pages
- `home.php` → Main homepage
- `db-error.php` → Database error page
- `env-error.php` → Environment error page
---
## 🧩 Templates
Reusable layout components:
- `templates/header.php`
- `templates/footer.php`
---
## 🧪 Status
🚧 This project is currently in development.
New features and improvements will be added progressively.
---
## 📌 Roadmap (Planned)
- [ ] Routing system
- [ ] Theme engine
- [ ] Admin panel structure
- [ ] CLI tools
- [ ] Environment (.env) support
- [ ] Basic authentication system
---
## 🤝 Contributing
Contributions, ideas, and feedback are welcome.
Feel free to open issues or pull requests.
---
## 📜 License
This project is licensed under the MIT License.
See the `LICENSE` file for details.
---
## 👤 Author
Created by Simone (SLD)
---
## 💡 Philosophy
This project aims to stay:
- Simple
- Transparent
- Framework-free
- Easy to extend
No magic, just clean PHP.

20
assets/css/animations.css Normal file
View File

@@ -0,0 +1,20 @@
@keyframes example {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
/* ### EXAMPLE SETTING CODE ###
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 2;
animation-direction: alternate-reverse;
animation-delay: -2s;
animation-fill-mode: forwards;
animation-timing-function: ease-in-out;}
### SAME ABOVE ANIMATION IN ONE LINE CODE ###
animation: example 5s linear 2s infinite alternate;
*/

18
assets/css/style.css Normal file
View File

@@ -0,0 +1,18 @@
html { scroll-behavior: smooth; }
*{ box-sizing: border-box; margin:0; padding:0;}
.main-nav{
display:flex;
width:100%;
gap: 1rem;
align-items: center;
justify-content: flex-start;
list-style-type: none;
padding:1rem;
}
.main-nav a {
text-decoration: none;
}

86
assets/css/variables.css Normal file
View File

@@ -0,0 +1,86 @@
:root {
/*### PrimaryColor ###*/
--demo1:hsl(98, 100%, 50%);/*Use this only to check the color (--pri) if is fine*/
--pri:98; /*Change only this from the color that you need! Don't Touch the code below!*/
/*The color below is automaticaly created 20 levels of lightness*/
--priCol20:hsl(var(--pri), 100%, 100%);
--priCol19:hsl(var(--pri), 100%, 95%);
--priCol18:hsl(var(--pri), 100%, 90%);
--priCol17:hsl(var(--pri), 100%, 85%);
--priCol16:hsl(var(--pri), 100%, 80%);
--priCol15:hsl(var(--pri), 100%, 75%);
--priCol14:hsl(var(--pri), 100%, 70%);
--priCol13:hsl(var(--pri), 100%, 65%);
--priCol12:hsl(var(--pri), 100%, 60%);
--priCol11:hsl(var(--pri), 100%, 55%);
--priCol10:hsl(var(--pri), 100%, 50%);
--priCol9:hsl(var(--pri), 100%, 45%);
--priCol8:hsl(var(--pri), 100%, 40%);
--priCol7:hsl(var(--pri), 100%, 35%);
--priCol6:hsl(var(--pri), 100%, 30%);
--priCol5:hsl(var(--pri), 100%, 25%);
--priCol4:hsl(var(--pri), 100%, 20%);
--priCol3:hsl(var(--pri), 100%, 15%);
--priCol2:hsl(var(--pri), 100%, 10%);
--priCol1:hsl(var(--pri), 100%, 5%);
/*### SecondColor ###*/
--demo2:hsl(207, 100%, 50%);/*Use this only to check the color (--pri) if is fine*/
--sec:207; /*Change only this from the color that you need! Don't Touch the code below!*/
/*The color below is automaticaly created 20 levels of lightness*/
--secCol20:hsl(var(--sec), 100%, 100%);
--secCol19:hsl(var(--sec), 100%, 95%);
--secCol18:hsl(var(--sec), 100%, 90%);
--secCol17:hsl(var(--sec), 100%, 85%);
--secCol16:hsl(var(--sec), 100%, 80%);
--secCol15:hsl(var(--sec), 100%, 75%);
--secCol14:hsl(var(--sec), 100%, 70%);
--secCol13:hsl(var(--sec), 100%, 65%);
--secCol12:hsl(var(--sec), 100%, 60%);
--secCol11:hsl(var(--sec), 100%, 55%);
--secCol10:hsl(var(--sec), 100%, 50%);
--secCol9:hsl(var(--sec), 100%, 45%);
--secCol8:hsl(var(--sec), 100%, 40%);
--secCol7:hsl(var(--sec), 100%, 35%);
--secCol6:hsl(var(--sec), 100%, 30%);
--secCol5:hsl(var(--sec), 100%, 25%);
--secCol4:hsl(var(--sec), 100%, 20%);
--secCol3:hsl(var(--sec), 100%, 15%);
--secCol2:hsl(var(--sec), 100%, 10%);
--secCol1:hsl(var(--sec), 100%, 5%);
/*### ThirdColor ###*/
--demo3:hsl(280, 100%, 50%);/*Use this only to check the color (--pri) if is fine*/
--thi:280; /*Change only this from the color that you need! Don't Touch the code below!*/
/*The color below is automaticaly created 20 levels of lightness*/
--thiCol20:hsl(var(--thi), 100%, 100%);
--thiCol19:hsl(var(--thi), 100%, 95%);
--thiCol18:hsl(var(--thi), 100%, 90%);
--thiCol17:hsl(var(--thi), 100%, 85%);
--thiCol16:hsl(var(--thi), 100%, 80%);
--thiCol15:hsl(var(--thi), 100%, 75%);
--thiCol14:hsl(var(--thi), 100%, 70%);
--thiCol13:hsl(var(--thi), 100%, 65%);
--thiCol12:hsl(var(--thi), 100%, 60%);
--thiCol11:hsl(var(--thi), 100%, 55%);
--thiCol10:hsl(var(--thi), 100%, 50%);
--thiCol9:hsl(var(--thi), 100%, 45%);
--thiCol8:hsl(var(--thi), 100%, 40%);
--thiCol7:hsl(var(--thi), 100%, 35%);
--thiCol6:hsl(var(--thi), 100%, 30%);
--thiCol5:hsl(var(--thi), 100%, 25%);
--thiCol4:hsl(var(--thi), 100%, 20%);
--thiCol3:hsl(var(--thi), 100%, 15%);
--thiCol2:hsl(var(--thi), 100%, 10%);
--thiCol1:hsl(var(--thi), 100%, 5%);
/*######################################*/
/*##### Default Variable #####*/
--padsidepage:0 25px; /*Padding side for page*/
}
/* ### Use Example ###
background-color:var(--main-bg-color)
*/

9
assets/js/main.js Normal file
View File

@@ -0,0 +1,9 @@
/* @ default js*/
function yearNow(textlocation) {
//This is a function to substitutes a value into the current year.
//Usually good for the footer.
var data = new Date();
var year;
year = data.getFullYear();
document.querySelector(textlocation).replaceWith(year);
}

36
config/constants.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
// --- ROOT DIR --- //
define("ASSETS_FOLD", ROOT_DIR . "assets/");
define("ADMIN_FOLD", ROOT_DIR . "admin/");
define("BLOCKNOTES_FOLD", ROOT_DIR . "blocknotes/");
define("CONFIG_FOLD", ROOT_DIR . "config/");
define("PAGES_FOLD", ROOT_DIR . "pages/");
define("PUBLIC_FOLD", ROOT_DIR . "public/");
define("TEMPLATES_FOLD", ROOT_DIR . "templates/");
define("THEMES_FOLD", ROOT_DIR . "themes/");
define("FUNCTIONS_FOLD", ROOT_DIR . "functions/");
define("INCLUDES_FOLD", ROOT_DIR . "includes/");
// - ASSETS
define("CSS_FOLD", ASSETS_FOLD . "css/");
define("IMG_FOLD", ASSETS_FOLD . "img/");
define("JS_FOLD", ASSETS_FOLD . "js/");
define("FONTS_FOLD", CSS_FOLD . "fonts/");
// --------------- //
// --- ROOT URL --- //
// - CSS
define("CSS_STYLE", ROOT_URL . "/assets/css/style.css");
define("CSS_VAR", ROOT_URL . "/assets/css/variables.css");
define("CSS_ANIM", ROOT_URL . "/assets/css/animations.css");
define("CSS_FONTS", ROOT_URL . "/assets/css/fonts.css");
// - JS
define("JS_MAIN", ROOT_URL . "/assets/js/main.js");
// --------------- //
?>

20
config/db.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
// Exceptions PHP-MSQLI
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
// Create Connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Connections Successfully
if(DB_DEBUG == "yes"){
echo "Connected successfully";
}
} catch (mysqli_sql_exception $e) {
// Access Deny
include(PAGES_FOLD . "db-error.php");
die();
}
?>

52
config/functions_init.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
function error_env($option) {
global $env;
if (empty($env)) {
$result = "<p class='err_env_result'><span>ERROR:</span> Variable '<u>\$env</u>' is empty!</p>";
$help = "<p class='err_env_help'>Please insert the correct value in the file 'config/init.php' or leave it to 'generic'</p>";
} else {
$result = "<p class='err_env_result'><span>ERROR:</span> The environment '<u>{$env}</u>' does not exist!</p>";
$help = "<p class='err_env_help'>Please insert the correct value in the file 'config/init.php' or leave it to 'generic'</p>";
}
echo $option === "result" ? $result : $help;
}
/**
* Get current page safely.
*/
function get_current_page() {
$page = $_GET["page"] ?? "home";
$page = strtolower(trim($page));
$page = preg_replace("/[^a-z0-9\-]/", "", $page);
if ($page === "") {
$page = "home";
}
return $page;
}
/**
* Resolve page file.
*/
function resolve_page() {
$page = get_current_page();
$file = PAGES_FOLD . $page . ".php";
// 👉 rendi disponibile globalmente
$GLOBALS["current_page"] = $page;
if (file_exists($file)) {
return $file;
}
http_response_code(404);
$GLOBALS["current_page"] = "404";
return PAGES_FOLD . "404.php";
}

26
config/init.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
include("config/functions_init.php");
$env="generic";
switch($env){
/*------ DON'T TOUCH THIS PART ------ */
case "generic":
define('WEB_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('DOMAIN', $_SERVER['HTTP_HOST']);
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
define('FULL_DOMAIN', $protocol . $_SERVER['HTTP_HOST']);
define("ROOT_URL", "http://" . DOMAIN );
define("ROOT_DIR", WEB_ROOT . "/");
break;
/* ----------------------------------- */
default:
// Showing error page by default.
$error_env_check=true;
include("pages/env-error.php");
die;
}
require_once(ROOT_DIR . "config/constants.php");
require_once(CONFIG_FOLD . "settings.php");
?>

29
config/settings.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
// -- GENERAL SETTING --
$debug="on";
// --- DB SETTINGS ---
$db_needed="no";
$db_debug="yes";
$db_host="localhost";
$db_name="database-name";
$db_user="database-user";
$db_pass="database-user-password";
//-------------------------------------------------------------------------------------
// --- DON'T CHANGE ALL THE CODE BELOW!!! ---
//-------------------------------------------------------------------------------------
// --- GENERAL SECTION CONFIGURATION
if ($debug == "on"){ define("DEBUG",true);} else { define("DEBUG", false); }
// --- DB SECTION CONFIGURATION
if ($db_needed == "yes"){
define("DB_HOST", $db_host);
define("DB_USER", $db_user);
define("DB_PASS", $db_pass);
define("DB_NAME", $db_name);
define("DB_DEBUG", $db_debug);
require_once(CONFIG_FOLD . "db.php");
}
?>

7
includes/head_links.php Normal file
View File

@@ -0,0 +1,7 @@
<link rel="stylesheet" href="<?= CSS_VAR ?>">
<link rel="stylesheet" href="<?= CSS_ANIM ?>">
<link rel="stylesheet" href="<?= CSS_STYLE ?>">
<script src="<?= JS_MAIN ?>"></script>

3
includes/js_footer.php Normal file
View File

@@ -0,0 +1,3 @@
<script>
yearNow("year");
</script>

7
index.php Normal file
View File

@@ -0,0 +1,7 @@
<?php
include("./config/init.php");
include(TEMPLATES_FOLD . "header.php");
include(resolve_page());
include(TEMPLATES_FOLD . "footer.php");
?>

4
pages/404.php Normal file
View File

@@ -0,0 +1,4 @@
<section>
<h1>404</h1>
<p>Page not found.</p>
</section>

1
pages/about.php Normal file
View File

@@ -0,0 +1 @@
<h1>About</h1>

76
pages/db-error.php Normal file
View File

@@ -0,0 +1,76 @@
<?php if ($db_needed !== "yes"){
header("Location: " . ROOT_URL );
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error Environment</title>
<style>
html{font-size: 20px; font-family:Cambria, Cochin, Georgia, Times, 'Times New Roman', serif}
*{ margin:0; padding:0;}
body{
width:100vw;
height:100vh; display:flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f8d5d5;
}
.container{
text-align: center;
background-color: #e6e6e6;
padding:100pt;
border: 4px solid #2b2b2b;
border-radius: 10px;
}
.err_env_result{
color:red;
margin:6px;
font-size: 30px;
}
.err_env_result > span{
font-weight: 600;
}
.err_env_help{
color: #880000;
}
.details{
font-style: italic;
margin-top:10px;
color: #272727;
font-size:17px;
}
.details > span{
color: #f30000;
font-weight: 600;
}
</style>
</head>
<body>
<div class="container">
<p class="err_env_result"><span>ERROR:</span> Can't establish a db connection!</p>
<p class='err_env_help'>Please check the db.php configurations.</p>
<?php
if (DB_DEBUG == "yes"){
echo "<p class=' details err_env_help'><span>Error Details: </span>" . $e->getMessage() . "</p>";
}
?>
</div>
</body>
</html>

55
pages/env-error.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
if (! $error_env_check){
header("Location: " . ROOT_URL );
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error Environment</title>
<style>
html{font-size: 20px; font-family:Cambria, Cochin, Georgia, Times, 'Times New Roman', serif}
*{ margin:0; padding:0;}
body{
width:100vw;
height:100vh; display:flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f8d5d5;
}
.container{
text-align: center;
background-color: #e6e6e6;
padding:100pt;
border: 4px solid #2b2b2b;
border-radius: 10px;
}
.err_env_result{
color:red;
margin:6px;
font-size: 30px;
}
.err_env_result > span{
font-weight: 600;
}
.err_env_help{
color: #880000;
}
</style>
</head>
<body>
<div class="container">
<?php
error_env('result');
error_env('help');
?>
</div>
</body>
</html>

0
pages/home.php Normal file
View File

7
templates/footer.php Normal file
View File

@@ -0,0 +1,7 @@
<footer class="main-footer">
<div class="footer-credit">&copy; <year>year</year> - Company Name. All right reserved.</div>
<div class="webmaster_footer">Website designed by Simone Cusano - SimoLinuxDesign.org</div>
</footer>
<?php include(INCLUDES_FOLD . "js_footer.php"); ?>
</body>
</html>

18
templates/header.php Normal file
View File

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include(INCLUDES_FOLD . "head_links.php"); ?>
<title><?php echo ucfirst($GLOBALS["current_page"] ?? "Home"); ?></title>
</head>
<body>
<header>
<ul class="main-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page1</a></li>
<li><a href="#">Page2</a></li>
<li><a href="#">Page3</a></li>
<li><a href="#">Page4</a></li>
</ul>
</header>