Skip to content

mahi07777/OnlineExamModule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Online Exam Module

A production-ready online examination system built with Core PHP and MySQL. Features include multi-language support (English, Marathi, Hindi), PDF certificate generation, and a comprehensive admin panel.

Features

  • Exam Management: Create and manage exams with customizable settings
  • Question Types: Multiple choice (single/multiple answer), True/False, Short Answer
  • Multi-language Support: English, Marathi, and Hindi translations
  • PDF Certificates: Auto-generated certificates for passing candidates
  • Timer & Auto-save: Real-time countdown with automatic answer saving
  • Admin Panel: Full CRUD for exams, questions, and viewing attempts
  • Security: CSRF protection, prepared statements, password hashing, rate limiting
  • Responsive Design: Bootstrap 5 for mobile-friendly interface

Requirements

  • PHP 7.4 or higher (compatible with PHP 8.x)
  • MySQL 5.7+ or MySQL 8.0+
  • Apache with mod_rewrite enabled
  • Composer (for PDF library installation)

Installation

1. Clone or Copy Files

Copy all files to your web server directory:

htdocs/OnlineExamModule/

2. Install Dependencies

Install TCPDF for PDF certificate generation:

cd OnlineExamModule
composer install

If you don't have Composer, download it here.

Note: The system will work without TCPDF, but will generate HTML certificates instead of PDF.

3. Create Database

Create a MySQL database for the exam module:

CREATE DATABASE exam_module CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

4. Run SQL Schema

Import the database schema:

mysql -u root -p exam_module < sql/schema.sql

Or use phpMyAdmin to import sql/schema.sql.

5. Load Sample Data (Optional)

Import sample exam data for testing:

mysql -u root -p exam_module < sql/seed_sample_data.sql

6. Configure Database Connection

Edit includes/db.php and update the database credentials:

define('DB_HOST', 'localhost');
define('DB_NAME', 'exam_module');
define('DB_USER', 'root');
define('DB_PASS', '');  // Your MySQL password

7. Set Permissions

Ensure the web server can write to the uploads directory (if you add file uploads):

chmod 755 -R OnlineExamModule

8. Access the Application

  • Student Interface: http://localhost/OnlineExamModule/public/
  • Admin Panel: http://localhost/OnlineExamModule/admin/

Default Admin Credentials

After running the schema, the default admin account is:

⚠️ Important: Change the admin password immediately after first login!

Directory Structure

OnlineExamModule/
├── admin/                  # Admin panel files
│   ├── index.php          # Dashboard
│   ├── exams.php          # Exam management
│   ├── questions.php      # Question management
│   ├── attempts.php       # View exam attempts
│   ├── settings.php       # System settings
│   ├── login.php          # Admin login
│   └── logout.php         # Admin logout
├── includes/              # Core PHP includes (protected)
│   ├── db.php             # Database connection
│   ├── auth.php           # Authentication functions
│   ├── csrf.php           # CSRF protection
│   ├── translator.php     # Translation functions
│   ├── exam_helper.php    # Exam business logic
│   └── pdf_generator.php  # Certificate generation
├── locale/                # Translation files (protected)
│   ├── en.json            # English
│   ├── mr.json            # Marathi
│   └── hi.json            # Hindi
├── public/                # Public-facing files
│   ├── css/style.css      # Custom styles
│   ├── js/app.js          # JavaScript
│   ├── index.php          # Exam listing
│   ├── exam.php           # Exam details
│   ├── start_exam.php     # Start exam
│   ├── take_exam.php      # Exam interface
│   ├── submit_exam.php    # Submit exam
│   ├── result.php         # Results page
│   ├── generate_certificate.php  # PDF certificate
│   ├── verify.php         # Certificate verification
│   ├── login.php          # User login
│   ├── register.php       # User registration
│   └── logout.php         # User logout
├── sql/                   # Database files (protected)
│   ├── schema.sql         # Database schema
│   └── seed_sample_data.sql  # Sample data
├── templates/             # HTML templates (protected)
│   ├── header.php         # Public header
│   ├── footer.php         # Public footer
│   ├── admin_header.php   # Admin header
│   └── admin_footer.php   # Admin footer
├── vendor/                # Composer packages (after install)
├── .htaccess              # Apache configuration
├── composer.json          # Composer configuration
└── README.md              # This file

Configuration

Database Settings

Edit includes/db.php:

define('DB_HOST', 'localhost');
define('DB_NAME', 'exam_module');
define('DB_USER', 'your_username');
define('DB_PASS', 'your_password');

Admin Settings

Access the admin panel at /admin/settings.php to configure:

  • Site name and logo
  • Default language
  • Guest exam permissions
  • Certificate customization
  • Email (SMTP) settings
  • Rate limiting

Adding Languages

  1. Create a new JSON file in /locale/ (e.g., fr.json for French)
  2. Copy structure from en.json
  3. Translate all strings
  4. Update the language selector in templates

API Endpoints

AJAX Save Answer

POST /public/ajax_save_answer.php

Parameters:

  • csrf_token - CSRF token
  • attempt_id - Attempt ID
  • question_id - Question ID
  • answer - User's answer

Response:

{
    "success": true,
    "message": "Answer saved"
}

Security Features

  1. CSRF Protection: All forms include CSRF tokens
  2. SQL Injection Prevention: Prepared statements via PDO
  3. XSS Prevention: Output escaping with htmlspecialchars()
  4. Password Security: password_hash() with bcrypt
  5. Session Security: HTTP-only cookies, session regeneration
  6. Rate Limiting: Configurable login attempt limits
  7. Directory Protection: .htaccess files block direct access

Exam Flow

  1. Student browses available exams on index page
  2. Student views exam details (duration, questions, passing score)
  3. Student enters name/email (guest) or logs in
  4. Timer starts, questions load one at a time
  5. Answers auto-save on selection
  6. Student navigates using question buttons
  7. Student submits exam
  8. System calculates score and determines pass/fail
  9. If passed, certificate is generated with unique ID
  10. Certificate can be verified via /public/verify.php

Customization

Styling

Edit public/css/style.css to customize the appearance. The module uses Bootstrap 5 CSS variables for easy theming.

Question Types

The system supports:

  • mcq_single - Multiple choice, single answer
  • mcq_multiple - Multiple choice, multiple answers
  • true_false - True/False
  • short_answer - Text input

Adding New Question Types

  1. Add type to the questions table type enum
  2. Update exam_helper.php calculateScore() function
  3. Update take_exam.php question rendering
  4. Update admin questions.php form

Troubleshooting

"CSRF token validation failed"

  • Clear browser cookies and try again
  • Ensure session storage is working

PDF not generating

  • Install TCPDF: composer install
  • Check write permissions
  • Falls back to HTML if TCPDF unavailable

Database connection failed

  • Verify credentials in db.php
  • Ensure MySQL is running
  • Check database exists

403 Forbidden errors

  • Check .htaccess configuration
  • Ensure mod_rewrite is enabled

Testing Checklist

  • Database connection works
  • Admin login functional
  • Can create/edit/delete exams
  • Can create/edit/delete questions
  • Student can browse exams
  • Student can start exam (guest mode)
  • Timer counts down correctly
  • Answers auto-save
  • Exam submits successfully
  • Score calculated correctly
  • Certificate generates (if passed)
  • Certificate verification works
  • Language switching works (EN/MR/HI)
  • Mobile responsive layout
  • All forms protected with CSRF

License

MIT License - feel free to use and modify for your projects.

Support

For issues or feature requests, please create an issue in the repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors