Title :
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories :
Algorithms , HTML and PHP , PHP , Variables
Ovidiu EFTIMIE
Date :
Feb 15th 2001
Grade :
2 of 5 (graded 4 times)
Viewed :
14753
File :
No file for this code example.
Images :
No Images for this code example.
Search :
More code by Ovidiu EFTIMIE
Action :
Grade This Code Example
Tools :
My Examples List
<?php
/****************************************************************
*Author: Ovidiu EFTIMIE
*Copyright:Ovidiu EFTIMIE
*Last modified:Friday, November 03, 2000 10:43:17 AM
*Description : Checks an array to see if it contains invalid chars
*****************************************************************/
class paranoia {
var $wrongParams = false ;
var $para =array( "~" , "`" , "!" , "@" , "#" , "\$" , "%" , "^" , "&" , "*" , "(" , ")" , "_" , "-" , "+" , "=" , "|" ,
"\\" , "{" , "}" , ":" , ";" , "\"" , "'" , "," , "<" , "." , ">" , "?" , "/" );
/**************************************************
*Class constructor
*Params : $paramsArray - the array containing the data to be checked
***************************************************/
function paranoia ( $paramsArray ){
reset ( $this -> para );
$this -> wrongParams = false ;
while(list( $k , $postvars )= each ( $paramsArray )){
if( is_array ( $postvars )){
while(list( $r , $postvals )= each ( $postvars )){
while(list(, $val )= each ( $this -> para )){
$wrong = strchr ( $postvals , $val );
if(!empty( $wrong )){
$this -> wrongParams = true ;
}
}
}
}else{
while(list(, $val )= each ( $this -> para )){
$wrong = strchr ( $postvars , $val );
if(!empty( $wrong )){
$this -> wrongParams = true ;
}
}
reset ( $this -> para );
}
}
return $this -> wrongParams ;
}
/*******************************************************
*Checks to see the invalid chars
********************************************************/
function checkParanoia (){
echo date ( "d M Y H:i:s" , time ()). "<br>Checking paranoia chars...<br><br>" ;
while(list( $d , $r )= each ( $this -> para )){
echo $d . ". <b>" . $r . "</b> = <b>" . ord ( $r ). "</b><br>" ;
}
}
/********************************************************
*Redirecting function
********************************************************/
function sendBack (){
echo '<html><head><title></title></head><body onLoad="javascript:history.back(-1);"></body></html>' ;
}
}
?>
=================================================
Example
=================================================
<?php
require_once( "paranoia.php" );
if(isset( $HTTP_POST_VARS )&&!empty( $HTTP_POST_VARS )){
$par =new paranoia ( $HTTP_POST_VARS );
if(!empty( $par -> wrongParams )){
// $par->sendBack();
echo "Incorrect parameters" ;
}else{
echo "Corect parameters" ;
}
}
?>
<html>
<head><title>Test page for paranoia</title></head>
<form action="test_paranoia.php" method="POST">
<input type="text" name="test">
<input type="submit" value="Test">
</form>
</html>
A quick way set data from a form to a function or other places where you can lose scope. Categories : PHP , HTML and PHP , Variables PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP , Email , PHP , Perl , HTML and PHP Paginating the mySQL data Categories : PHP , Algorithms , Databases , MySQL , HTML and PHP Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays , Global Variables , PHP , HTML and PHP , Variables Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP , HTML and PHP , Global Variables , Cookies , Variables A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP , Databases , Algorithms , PHP , MySQL A class to put get and post variables in hidden form
elements. Works on scalars, normal arrays, associative
arrays. Categories : Algorithms , Variables , Arrays , PHP , PHP Classes IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival. Categories : PHP , Algorithms , Security , URLs Multiple Select box, Select multiple Items from Menu.List box Categories : PHP , HTML and PHP , Beginner Guides mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP , Beginner Guides , MySQL , HTML and PHP , Databases Timer - a class that uses microtime() to provide easy calculation of elapsed times Categories : Algorithms , PHP , PHP Classes This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field Categories : PHP , MySQL , Java Script , HTML and PHP Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP , Directories , FTP , Filesystem , HTML and PHP Prime number finder (Sieve of Erastothenes) Categories : PHP , Algorithms , Math. Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP , PHP , Strings