Version: 1.0

Type: Full Script

Category: File Management

License: GNU General Public License

Description: PHPScrambler enables you to make your ready-to-use php files hard to read. This makes (at least) some hope that the code user (client) can't use your code for his own benefits. PHPScrambler by Sven Kirsime LLC Accuro Web-Systems / Special software / Consultations mail: sven.kirsimae@accuro.ee web: http://www.accuro.ee



<?
/**
* PHPScrambler by Sven Kirsime
* LLC Accuro
* sven.kirsimae@accuro.ee
* Estonia
*
* THIS CODE IS (OF COURSE) FREE TO USE :) !
*
* Simple php file source scrambler.
* Simply removes comments and newlines
* from php files making them hard to read :)
* but keeps them working.
*
* When using PHPScramble always keep the original
* PHP code because scrambled code can be hard
* to read even for the code creator or at least
* for the case if the scrambler will not work :| !
*
* When code is scrambled, just rename the scrambled
* file as the original one (remove 'cr' extension)
* and take it in use.
*
* !!!!!!! SCRAMBLE FILE FORMAT !!!!!!!
*
* All the comment has to be on their own line!
*
* WRONG WAY OF COMMENTING:
* if (doFunction()){ //This 'if' does that
*  ...
* } //if
*
* HAS TO BE:
* //This if does that
* if (doFunction()){
*  ...
* }
* // if
*
* If this type of commenting not followed, the
* scrambler can scramble the file, but the php code
* may fail to work!
*
* In order to change comments into the right
* ones, simply make search for '//'
* in php file and move [Enter] all '//' styled
* comments to new line.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

//------ File to scramble ---------
$inFile = "someFileName.php";
//---------------------------------
//------ Out file extension -------
$outFileExt = ".cr";
//---------------------------------


//Checking if the input file exists
if (is_file($inFile)){
    //Get the file as array of lines
    $rowsFromFile = file($inFile);
    //Make scrambling
    $newContent = scramble($rowsFromFile);

    //Write scrambled file
    $outFile = $inFile.$outFileExt;
    $fp = fopen($outFile,"w+");
    $ret = fwrite($fp, $newContent);
    fclose($fp);
    if ($fp == false){
        echo ("<hr><center><b>THERE WAS AN ERROR READING THE FILE $inFile! SCRAMBLE WAS NOT DONE!</b></center><hr>");
    } else
    if ($ret == -1){
        echo ("<hr><center><b>THERE WAS AN ERROR WRITING THE FILE $outFile! FILE WAS NOT WRITEN!</b></center><hr>");
    } else {
        echo("<hr><center><b>File $inFile is scrambled as $outFile</b></center><hr>");
    }
} else {
    echo("<hr><center><b>YOU HAVE TO SET A FILE TO SCRAMBLE!<br>THE ONE THAT IS SET ($inFile) ISN'T A FILE OR DOES NOT EXIST!<br>SET \$inFile AS AN INPUT FILE TO SCRAMBLE!</b></center><hr>");
}
echo ("<center><br>Thanks for using PHPScrabler by <a href=\"mailto:sven.kirsimae@accuro.ee\">Sven Kirsim&auml;e</a> <a href=\"http://www.accuro.ee\" target=\"_blank\">//Accuro</a><br>Web-Systems / Special software / Consultations<br></center></hr>");

/**
*  Function that does the scrambling.
*  Returns scrambled text
*/
function scramble($rowsToScramble){
    $newContent = "";
    while (list($key, $val) = each($rowsToScramble)){
        $val = trim($val);
        //Leave out comments
        if (!preg_match("/^[\/\/]+/", $val) &&
           (!preg_match("/^\/[\*]+/", $val)) &&
           (!preg_match("/^[\*]+/", $val)) &&
           (!preg_match("/^[\*]+\//", $val))
        ){
             $newContent .= $val."\n";
        }
    }
    //Replace newlines with one space
    $newContent = preg_replace("/\n/", " ", $newContent);
    //Return th scrambled text
    return $newContent;
}
?>