PHP Classes

File: testThis.class.php

Recommend this page to a friend!
  Classes of BrettsBSD.net   testThis.class.php   testThis.class.php   Download  
File: testThis.class.php
Role: ???
Content type: text/plain
Description: Main class file
Class: testThis.class.php
Author: By
Last change:
Date: 23 years ago
Size: 3,187 bytes
 

Contents

Class file image Download
<? /** * Brett D. Estrade * 3/29/2001 * brett@mvdev.com * http://www.mvdev.com * This class is designed to let you easily implement required constraints on your php applications * * You can use this class as long as you keep this header up here along with a summary of any modifications * that you have made. * * Also, if you have any suggestions on how to improve this, please email me with a detailed suggestion. * If there is a bug or vulnerability found, please alert me immediately */ class testThis { /** * Tests constraint provided by user. Levels can be extended simply by adding to the switch statement */ function constraint($reqConstraint = '1 == 1',$requireLevel,$errMsg = '') { /** * Test for illegal code; Attempts to prevent insertion of other * types of code for execution by searching for a "}"; */ if(ereg('}',$reqConstraint)) { Die('Illegal character "}" found.'); } /** * Switch that checks for $requireLevel. Add more for extended functionality */ switch($requireLevel) { case 1: // returns error and kills script process if false $str = 'if ('.$reqConstraint.'){return true;}else{die(\''.$errMsg.'\');}'; eval($str); break; case 2: // just returns false and error if false $str = 'if ('.$reqConstraint.'){return true;}else{echo \''.$errMsg.'\'; return false;}'; eval($str); break; default: die('Level <b>'.$requireLevel.'</b> not defined.<br>Script Terminated...good bye!'); break; } } /** * The following are methods that utilize the constraint method above. There are many ways that this can * be used, and the following are just a couple of them */ /** * Requires file provided by user. Levels can be extended simply by adding to the switch statement to this->constraint * First, existance of file is checked. If that is true, the it uses the constraint method to perform the inclusion of the file * If file does not exist, the constraint function is called, this time with a predermined 'false' inserted, and it handles the rest */ function includeFile($file = '',$requireLevel = 1,$errMsg = ''){ if (file_exists($file)){ $this->constraint('@include('.$file.')',$requireLevel,$errMsg); } else { $this->constraint('false',$requireLevel,$errMsg); } } /** * Requires file provided by user. Levels can be extended simply by adding to the switch statement to this->constraint * First, existance of file is checked. If that is true, the it uses the constraint method to perform the inclusion of the file * If file does not exist, the constraint function is called, this time with a predermined 'false' inserted, and it handles the rest */ function requireFile($file = '',$requireLevel = 1,$errMsg = 'Required file does not exist Script Terminated...good bye!'){ if (file_exists($file)){ $this->constraint('@require('.$file.')',$requireLevel,$errMsg); } else { $this->constraint('false',$requireLevel,$errMsg); } } } ?>