Sustainability Tracking & Certification Web Application
Empowering organisations to measure, track, and showcase their environmental impact โ with structured scoring, digital certificates, and community engagement.
๐ Getting Started ยท โจ Features ยท ๐งช Tests ยท ๐ก๏ธ Security ยท ๐๏ธ Database
GreenScore is a full-stack sustainability platform built with PHP and MySQL. Organisations complete a structured environmental assessment across 10 categories, earn one of 14 progressive badge levels, and receive official downloadable certificates โ Gold, Silver, Bronze, or Participation โ based on their cumulative performance.
The platform includes a community tip board, a user feedback system, a secure contribution flow for upgrading certificates, a comprehensive admin dashboard, dark mode, and a full toast notification system โ all built with a strong emphasis on security best practices.
๐ Developed as part of the Graded Unit 2 Software Development assessment at Edinburgh College โ Academic Year 2024/2025.
| Feature | Description |
|---|---|
| ๐ Authentication | Registration, login, logout, password reset, session-based role management |
| ๐งฎ Green Calculator | 10-category assessment rated RED / AMBER / GREEN โ score out of 100 |
| ๐ 14 Badge Levels | Progressive badges from Green Starter to Champion of Sustainability |
| ๐ Certificates | Gold / Silver / Bronze / Participation โ real submission date, company name, certificate ref number, print-to-PDF |
| ๐ Certificate History | Responsive card layout โ colour-coded by award, score bar, filter by level, sort by date |
| ๐ธ Buy Points | Contribute to close a score gap and upgrade a certificate to Gold |
| ๐ My Impact | Personal dashboard โ badge level, green answer count, contribution total, progress bar |
| ๐ Community Board | Paginated tip board with keyword search, character counter, create/edit/delete per user |
| ๐ฌ Feedback System | User submission with admin response panel and public visibility toggle |
| ๐ฅ Admin Dashboard | Role/status management, user editing, feedback moderation |
| ๐ Dark Mode | Full dark mode with localStorage persistence across page navigation |
| ๐ Toast Notifications | Dismissible floating toasts sitewide โ success, error, warning, info |
Security was a core design priority throughout development:
| Protection | Implementation |
|---|---|
| Password hashing | password_hash() with bcrypt โ auto-salted, unique per user |
| SQL injection | Prepared statements with bound parameters across all 44 PHP files |
| CSRF protection | Token generated once per session in init.php, validated on every state-changing form |
| Session fixation | session_regenerate_id(true) immediately on login; periodic regeneration every 15 min |
| Idle timeout | Session destroyed after 30 minutes of inactivity |
| Login rate limiting | IP blocked after 5 failed attempts in 15 minutes โ recorded in login_attempts table |
| Password complexity | Min 8 chars, uppercase + lowercase + number required, common passwords blocked |
| Cookie flags | HttpOnly, SameSite=Strict on session cookie |
| Security headers | X-Frame-Options: DENY, X-Content-Type-Options, Referrer-Policy, X-XSS-Protection, Permissions-Policy |
| Role-based access | Admin routes return HTTP 403 if accessed without correct session role |
| Output sanitisation | All user data escaped with htmlspecialchars() before rendering |
.htaccess |
Blocks direct GET to includes/, blocks .sql/.env/.log files, custom 403/404 pages |
| Layer | Technology |
|---|---|
| Backend | PHP 8.2 |
| Database | MySQL / MariaDB via XAMPP |
| Frontend | HTML5, CSS3, JavaScript (ES6) |
| UI Framework | Bootstrap 5.3 |
| Icons | Font Awesome 6.4 |
| Testing | PHPUnit 11.5 (via phar) |
| Dev Environment | XAMPP, phpMyAdmin, PHPStorm |
Six tables with foreign key constraints and cascading deletes:
| Table | Purpose |
|---|---|
new_users |
Accounts, roles (admin/user), statuses, company details |
green_calculator_results |
Scores, award levels, badge data, donation records |
community_tips |
User-submitted tips with ownership |
feedback |
Messages, admin responses, public visibility flag |
credit_cards |
Saved card details per user |
login_attempts |
IP-based rate limiting records |
The full schema with seed data is available at database/gradedunit.sql.
/
โโโ index.php โ Home page
โโโ style.css โ Global stylesheet (CSS variables, dark mode, responsive)
โโโ .htaccess โ Security rules, error routing
โโโ 403.php / 404.php โ Custom error pages
โโโ assets/
โ โโโ favicon.svg
โ โโโ images/ โ Backgrounds, 14 badge illustrations, partner logos
โ โโโ documents/ โ Downloadable PDF guides
โโโ includes/
โ โโโ init.php โ Session bootstrap, security headers, CSRF, BASE_URL
โ โโโ connect_db.php โ Database connection
โ โโโ nav.php โ Navigation (active highlighting, dark mode toggle)
โ โโโ footer.php โ Toast system, back-to-top, dark mode JS
โ โโโ head.php โ Favicon, theme-color, stylesheet links
โ โโโ helpers.php โ isActive(), renderEditButton(), renderRoleStatusForms()
โ โโโ login_tools.php โ validate() with password_verify
โ โโโ login_action.php โ Login POST handler with rate limiting
โ โโโ modals.php โ Register/login modal components
โโโ pages/
โ โโโ auth/ โ login, logout, register, register_action, forgot_password
โ โโโ admin/ โ admin_feedback, manage_users, edit_user, public_feedback, process_feedback_admin
โ โโโ calculator/ โ green_calculator, certificate_history, certificate_preview, buy_points
โ โโโ community/ โ community, post_tip, edit_tip, delete_tip, clear_tips
โ โโโ user/ โ user_account, my_impact, view_cards, manage_credit_card
โ โโโ info/ โ about, partner, privacy, terms, green_resources, feedback, greenscore_copyright
โโโ database/
โ โโโ gradedunit.sql โ Full schema with seed data
โโโ tests/
โโโ LoginTest.php
โโโ GreenCalculatorTest.php
โโโ CommunityTipsTest.php
โโโ PaymentTest.php
โโโ fake_login_tools.php โ Session simulation helper for testing
42 tests โ 63 assertions โ all passing
| Test Class | What it covers |
|---|---|
LoginTest |
password_verify() path, correct session keys, wrong password, unknown email, admin role |
GreenCalculatorTest |
All 4 award thresholds by boundary value, all-green/amber/red scoring, shortfall and cost |
CommunityTipsTest |
Message validation, trimming, HTML escaping, auth guard, ownership check, pagination |
PaymentTest |
Cost from shortfall, clamping (min/max), formatting, float conversion, post-payment state |
A fake_login_tools.php helper simulates authenticated session state for testing protected routes without a live database connection.
php phpunit.phar --testdox --colors=never- XAMPP with Apache + MySQL
- PHP 8.2+
git clone https://github.com/Lancelcode/Graded-Unit-2-webpage.git- Start Apache and MySQL in the XAMPP control panel
- Place the project folder in
C:/xampp/htdocs/
- Open phpMyAdmin at
http://localhost/phpmyadmin - Create a database named
gradedunit - Import
database/gradedunit.sql - Default credentials in
includes/connect_db.php: hostlocalhost, userroot, password empty
http://localhost/Graded-Unit-2-webpage/
| Role | Password | |
|---|---|---|
| Admin | [email protected] |
(set in your DB) |
| User | [email protected] |
(set in your DB) |
Djiby Sow Rebollo
Edinburgh College โ Software Development Graded Unit 2 โ Academic Year 2024/2025
This project is licensed under the MIT License.
Built with ๐ to make sustainability measurable.