|
|
|
| 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 : |
8819 |
| 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 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 quick way set data from a form to a function or other places where you can lose scope. Categories : PHP, HTML and PHP, Variables | | | Paginating the mySQL data Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP | | | 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 | | | 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 | | | 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 simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Calendar using Date function Categories : HTML and PHP, PHP, Date Time, Calendar | | | PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions | |
|
|
|