Anti-scraping PHP Handler
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
css-balagan
css
items
src
.gitignore
LICENSE.md
README.md
_config.yml
analyticstracking.php
composer.json
composer.lock
examples.php

README.md

Balagan - anti scraping (HTML) PHP library

Balagan is a PHP library used to protect precious values and to prevent the scraping of your HTML content.

It generates HTML fake contents, nodes and other tricks in order to dupe any scraper.

Features

  • Create a "Balagan" (c.f. bloody mess) on your HTML content.
  • Protect your data putting some Balagan content that doesn't mean anything around and inside the value itself.
  • Generate randomly CSS class names, new random nodes, fake and invisible html content.
  • HTML tags are replaced, CSS generated on the fly.
  • All the content that is generated is invisible from all browsers.

Demo

go to jackydan.com/balagan and run your debugger (Inspecting elements) to see.

Installation

$ cd yourProject
$ git clone git@github.com:jackydan/balagan.git
$ sudo chown -R www-data css-balagan/

File Structure

├── composer.json
├── composer.lock
├── css
│   └── style.php
├── css-balagan             # Balagan's generated files
│   ├── css-basics.php      # Require write/read permission for www-data
│   └── css-variables.php   # Require write/read permission for www-data
├── examples.php
├── items 
│   └── items.php           # Return php array of items
├── README.md
└── src
    ├── Balagan.php         # Main class
    └── BasicCss.php        # Other class

Example

You could run examples.php on your browser, or copy-paste the example files below:

Example with a table of items

on index.php

<html>
<head>
    <meta charset="UTF-8">
    <link href="path/to/css/style.php" rel="stylesheet">
</head>
<body>

<?php 

// Require main Class
require_once 'path/to/src/Balagan.php';

// Object creation
$balagan = new Balagan(true);

// Creation of the table, tr and td
$table  = $balagan->table();
$tr     = $balagan->tr();
$td     = $balagan->td();

/**
 * 2 choices for injecting CSS:
 * - Write some CSS directly on the generateCssClass() call
 *                          OR
 * - Generate a CSS class which you will put into a "class" attribute
 * The 2 examples are shown below.
 */
 
// Injecting CSS directly on the html tag creation
$th     = $balagan->th('border: 1px solid black; padding: 3px; font-size: 20px');

// Or Generating CSS Classes
$tableClass = $balagan->generateCssClass("border: 1px solid black; list-style-type: none; padding: 20px; margin: 0 auto; width: 12%;");

$tdClass    = $balagan->generateCssClass("padding: 3px; font-weight: bold; text-align: center; border: 1px solid gray;");

// Item values
$value_1 = $balagan->superTag("770$");
$value_2 = $balagan->superTag("26$");

$htmlTable = "
<h1 style='text-align: center'>Example with table, th, tr & td</h1>
        <$table class='$tableClass'>
          <$tr>
            <$th>Month</$th>
            <$th>Savings</$th>
          </$tr>
          <$tr>
            <$td class='$tdClass'>November</$td>
            <$td class='$tdClass'>$value_1</$td>
          </$tr>
          <$tr>
            <$td class='$tdClass'>December</$td>
            <$td class='$tdClass'>$value_2</$td>
          </$tr>
        </$table>";
echo $htmlTable;
$balagan->exec();
?>

On style.php

<?php

require_once '../path/to/src/Balagan.php';

Balagan::getBasicCss();
header("Content-type: text/css; charset: UTF-8");

Todo

  • Write more HTML Tags functions and increase BasicCss Class(a, strong, ...)
  • Think about js for peoples who want to get these tags.

License

MIT

Free Software, Hell Yeah!