Skip to content

The PHP Form Handler Library is designed to fortify form data processing by implementing robust security measures, including variable sanitization, XSS (Cross-Site Scripting) attack prevention, and CSRF (Cross-Site Request Forgery) token management.

Notifications You must be signed in to change notification settings

hashaam-zahid/php-form-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Form Handler Library

The PHP Form Handler Library is designed to fortify form data processing by implementing robust security measures, including variable sanitization, XSS (Cross-Site Scripting) attack prevention, and CSRF (Cross-Site Request Forgery) token management.

Author

Hashaam Zahid

Key Features

Variable Sanitization:

Prevents malicious code injection by filtering form input data to remove potentially harmful characters.

XSS Attack Prevention: Utilizes PHP's filter library and HTML encoding techniques to defend against Cross-Site Scripting attacks.

CSRF Token Management: Implements CSRF token generation and validation to safeguard against Cross-Site Request Forgery attacks.

Goal

The primary objective of this repository is to provide a secure and reliable PHP library for handling form submissions. It empowers developers to:

Safely process form input data by filtering and sanitizing variables. Protect web applications from XSS vulnerabilities by filtering out malicious input. Implement CSRF tokenization to ensure secure and authenticated form submissions.

Folder Structure

│
├── src/
│   ├── FormHandler/
│   │   ├── FormHandler.php
│   │   ├── Validation/
│   │   │   └── Validator.php
│   │   └── Security/
│   │       └── CSRFToken.php
│   │
│   └── ... (other library files)
│
├── test_form_handler.php  <-- Your test file here
├── composer.json
└── vendor/
   └── ... (Composer dependencies)

Features

  • Input Filtering: Sanitize form input data to prevent malicious code injection.
  • Form Validation: Validate form fields to ensure required data is present and in the correct format.
  • CSRF Protection: Guard against Cross-Site Request Forgery attacks using tokens.

Setup

Use Xampp, Mampp any Server with start with 127.0.0.1

Installation via Composer

  1. Install the library using Composer:

    composer require hashaam-zahid/php-form-handler
  2. Include the Composer autoloader in your PHP script:

    require_once 'vendor/autoload.php';

Manual Installation

  1. Clone the repository:

    git clone https://github.com/hashaam-zahid/php-form-handler.git
  2. Include the necessary files in your PHP project:

    require_once 'path/to/vendor/autoload.php';

Usage

Instantiate the FormHandler class and use its methods to process form submissions securely.

Example:

// Include autoload file
require_once 'path/to/vendor/autoload.php';

use FormHandler\FormHandler;

$formHandler = new FormHandler\FormHandler();

// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $postData = $_POST;

    // Filter form input data
    foreach ($postData as $key => $value) {
        $postData[$key] = $formHandler->sanitizeInput($value);
    }

    // Handle form submission
    $result = $formHandler->handleForm($postData);

    if ($result['success']) {
        // Form submitted successfully
        echo $result['message'];
    } else {
        // Form submission failed
        echo $result['message'];
    }
}

Contributing

Contributions are welcome! Feel free to fork the repository, make changes, and create pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

This updated README.md includes detailed feature descriptions, comprehensive setup instructions using Composer or manual installation, usage guidelines, information about contributing, the author, and the license details. hashaam-zahid in the installation instructions with your actual GitHub username or organization name. Adjust the paths and additional details according to your project's structure and requirements.

About

The PHP Form Handler Library is designed to fortify form data processing by implementing robust security measures, including variable sanitization, XSS (Cross-Site Scripting) attack prevention, and CSRF (Cross-Site Request Forgery) token management.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages