|
|
|
| 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 : |
12004 |
| 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> | | |
|
| 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 | | | 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 | | | 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 | | | 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 | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | | | 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 | | | TreeView - Finally a working tree view function to be used as you want. Simple create the Table using the code provided and you will be able to have a tree view in your project. Download the zip to get the images. Categories : PHP, HTML and PHP, Navigation | | | Using PHP im HTML image tags Categories : PHP, HTML and PHP, Graphics, Beginner Guides | | | This script allows people to add their favorite quotes to your website. This
could easily be modified to be a guestbook script or comment page script. Categories : PHP, Complete Programs, HTML and PHP, Misc | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Function to convert Arabic numbers into Roman Numerals Categories : Algorithms, PHP, Date Time | | | Amazon book cover handling Categories : HTML and PHP, PHP, MySQL, Ecommerce | | | This functions compares the current PHP version with a
desired version. Because of the 3 tiered version system, a
direct compare of a string to phpversion() will not be
accurate. Categories : PHP Configuration, PHP, Variables | |
|
|