Compare commits

...

5 Commits

13 changed files with 247 additions and 27 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.

View File

@@ -1,22 +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>' not exists!</p>";
$help="<p class='err_env_help'>Please insert the correct value in the file 'config/init.php or leave it to 'generic'</p>";
$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>";
}
if($option == "result"){
echo $result;
}elseif($option == "help"){
echo $help;
}else{
echo "ERROR: Wrong attribute in declared in the function!";
die;
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";
}
?>

View File

@@ -1,5 +1,6 @@
<?php
$env="";
include("config/functions_init.php");
$env="generic";
switch($env){
/*------ DON'T TOUCH THIS PART ------ */
@@ -13,7 +14,8 @@
break;
/* ----------------------------------- */
default:
include("config/functions_init.php");
// Showing error page by default.
$error_env_check=true;
include("pages/env-error.php");
die;

View File

@@ -1,4 +1,7 @@
<?php
// -- GENERAL SETTING --
$debug="on";
// --- DB SETTINGS ---
$db_needed="no";
$db_debug="yes";
@@ -7,9 +10,14 @@ $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); }
// --- DON'T CHANGE ALL THE CODE BELOW ---
// --- DB SECTION CONFIGURATION
if ($db_needed == "yes"){
define("DB_HOST", $db_host);
define("DB_USER", $db_user);
@@ -17,6 +25,5 @@ if ($db_needed == "yes"){
define("DB_NAME", $db_name);
define("DB_DEBUG", $db_debug);
require_once(CONFIG_FOLD . "db.php");
}
?>

View File

@@ -1,6 +1,7 @@
<?php
include("./config/init.php");
include(ROOT_DIR . "/templates/header.php");
include("./pages/home.php");
include("./templates/footer.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>

View File

@@ -1,3 +1,7 @@
<?php if ($db_needed !== "yes"){
header("Location: " . ROOT_URL );
}
?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@@ -1,3 +1,8 @@
<?php
if (! $error_env_check){
header("Location: " . ROOT_URL );
}
?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include(INCLUDES_FOLD . "head_links.php"); ?>
<title>Document</title>
<title><?php echo ucfirst($GLOBALS["current_page"] ?? "Home"); ?></title>
</head>
<body>
<header>