for clone git clone -b url_refine https://github.com/imanpr33trai/cls-pnb.git cd cls-pnb composer i
This project has been updated to use SEO-friendly and readable URLs (slugs) instead of ID-based URLs.
Old URL Examples:
product.php?id=123single-ad.php?ad_id=456single-article.php?id=789
New URL Examples:
/products/(for ad listings, handled byproduct.php)/ads/ad-title-slug//articles/article-title-slug//categories/category-name-slug/
To support the new URL structure, the following slug columns have been added to the respective tables:
ad_formtable: Addedad_slug(VARCHAR(255) UNIQUE)blog_poststable: Addedblog_slug(VARCHAR(255) UNIQUE)
Action Required: If you are setting up this project, ensure your database schema is updated to include these new columns. You can find the ALTER TABLE statements in schema-update.sql.
This outline details recommended changes to prepare the application for a production environment.
- SQL Injection Vulnerabilities:
- Files:
partials/search-hero.php,partials/voice-search.php,partials/get_subcategories.php. - Issue: These files directly insert user input into database queries without using prepared statements, creating a critical security risk.
- Action: Rewrite all database queries in these files to use prepared statements (
prepare,bind_param,execute).
- Files:
- Cross-Site Scripting (XSS) Prevention:
- Issue: User-provided data (
$_POST,$_GET) is not consistently sanitized before being displayed on the page. - Action: Review all
echostatements and ensurehtmlspecialchars()is used for any user-controllable data to prevent XSS attacks.
- Issue: User-provided data (
- Remove Debugging Code:
- Files:
app/auth/login.php,app/auth/logout.php,app/auth/register.php,app/auth/verify.php. - Issue: These files contain active or commented-out debugging code (
echo,print_r, etc.) that should not be in production. - Action: Remove all debugging statements.
- Files:
- Disable Public Error Display:
- File:
app/auth/login.php. - Issue:
ini_set('display_errors', 1)is active, which can reveal sensitive server information. - Action: This setting should be disabled in production. Global error reporting settings should be managed centrally in
config/config.php.
- File:
- Consistent Error Handling:
- Issue: Error handling is inconsistent across the application (e.g.,
die(), session messages, directecho). - Action: Implement a unified error handling strategy. Log system-level errors to a file and show user-friendly messages for UI errors.
- Issue: Error handling is inconsistent across the application (e.g.,
- Redundant File Inclusions:
- Issue: Some files use
includeinstead ofinclude_once, which can lead to "cannot redeclare function" errors if a file is included multiple times. - Action: Use
include_onceorrequire_oncefor all file inclusions to ensure they are loaded only once.
- Issue: Some files use
- Separation of Concerns:
- Issue: PHP logic is heavily mixed with HTML markup, making the code difficult to maintain.
- Action (Short-term): Restructure files to have a dedicated PHP block at the top for all logic (database queries, form processing), storing results in variables. The HTML below should then use these variables for display.
- Hardcoded URLs:
- Issue: Some files contain hardcoded URLs instead of using the global base URL variable.
- Action: Update all URLs to be dynamically generated using the
$base_urlvariable defined inconfig/config.php.
This section provides a high-level overview of the application's structure and a checklist for deploying to a production environment.
This directory is the application's foundation.
-
config.php:- Purpose: Initializes the entire application. Loads environment variables (
.env), establishes the database connection, and configures the session handler. - Production Action: Ensure the
.envfile exists on the server with correct production database credentials, API keys, and SMTP settings. The.envfile must never be committed to version control.
- Purpose: Initializes the entire application. Loads environment variables (
-
debug.php:- Purpose: Provides a detailed debugging and error-handling system for development.
- Production Action: Set the
IS_DEVELOPMENT_MODEconstant tofalse. This will disable all on-screen error reporting and debug outputs, preventing potential information leaks. Error logging tologs/debug.logwill continue.
-
functions.php:- Purpose: Contains global helper functions like
create_unique_slug(). - Production Action: No changes needed, but ensure any new helpers are generic and well-documented.
- Purpose: Contains global helper functions like
This directory manages the entire user lifecycle.
- Files:
login.php,register.php,verify.php,logout.php. - Purpose: Handles user sign-in, new account creation, OTP email verification, and sign-out. It integrates with Google and GitHub for social logins.
- Production Action:
- Remove Debug Code: Purge all commented-out or active
echo,print_r, andvar_dumpstatements. - User-Friendly Errors: Ensure that error messages shown to the user (e.g., "Invalid email or password") are generic and do not reveal whether an email address exists in the system.
- Remove Debug Code: Purge all commented-out or active
These are the primary user-facing views of the application.
- Files:
home.php,ad-form.php,Blog-form.php,single-ad.php,single-article.php, etc. - Purpose: These files are responsible for fetching data from the database and rendering the main content of the application. They follow a consistent pattern:
- Include
config.php. - Perform all necessary PHP logic (database queries, form processing).
- Include
header.php. - Render the HTML body, using the data fetched in the logic block.
- Include
footer.php.
- Include
- Production Action:
- Secure All Queries: Confirm that every database query uses prepared statements (
prepare,bind_param,execute) to prevent SQL injection. - Escape All Output: Ensure all data echoed into the HTML from the database or user input is sanitized with
htmlspecialchars()to prevent XSS attacks.
- Secure All Queries: Confirm that every database query uses prepared statements (
This directory contains snippets of UI used across multiple pages.
- Files:
header.php,footer.php,hero-sec.php,category-sec.php, etc. - Purpose: To provide consistent and reusable parts of the user interface.
- Production Action:
- CRITICAL - Remove Insecure Scripts: The files
partials/search-hero.phpandpartials/voice-search.phpcontain severe SQL injection vulnerabilities. They should be deleted immediately, as their functionality has been replaced by secure AJAX handlers. - CRITICAL - Consolidate JavaScript: The
footer.phpcontains multiple, conflicting, and redundant JavaScript blocks. This will lead to unpredictable behavior. All page-specific JavaScript should be moved into a single, well-organized file (e.g.,assets/js/main.js) and included once. The current inline scripts should be removed. - Cleanup: Delete legacy handlers like
partials/submit_review.phpthat have been replaced by AJAX endpoints.
- CRITICAL - Remove Insecure Scripts: The files
This directory is the designated location for all server-side logic that responds to client-side JavaScript requests.
- Purpose: To provide clean, JSON-based responses for dynamic page updates (e.g., submitting comments, fetching search results, loading posts by category).
- Production Action:
- Enforce AJAX Mode: Every file in this directory must begin with
define('AJAX_REQUEST', true);to disable the HTML-based error reporting fromdebug.php. - Standardize Responses: All endpoints should return JSON objects (e.g.,
{"success": true, "data": [...]}or{"success": false, "message": "Error"}). They should neverechoraw HTML or strings.
- Enforce AJAX Mode: Every file in this directory must begin with
- Dependencies:
- Run
composer install --no-dev --optimize-autoloaderon the server to install only production PHP dependencies. - Run
npm installandnpm run build(or equivalent) to compile and minify production CSS and JavaScript assets.
- Run
- Environment File: Create the
.envfile on the production server with the correct database, mail, and API credentials. - Configuration: In
config/debug.php, setIS_DEVELOPMENT_MODEtofalse. - Permissions: Ensure the
logs/andassets/uploads/directories are writable by the web server. - Cron Job: Set up a cron job on the server to periodically run the
partials/update_ad_status.phpscript to handle ad expirations.