WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : filter untrusted GET and POST variables and create trusted variable of same name
Categories : PHP, Global Variables, Security Click here to Update Your Picture
Tim Morton
Date : May 26th 2003
Grade : 5 of 5 (graded 2 times)
Viewed : 9279
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Tim Morton
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This function will allow you to take $_GET, $_POST, and $_COOKIE variables,
filter them (is alpha, is number, is email, etc.)
and returns the variable in scope.

<?php
function assign($variable,$type,$restrictions) {
   
$temp='';
    switch(
$type) {
        case
'get':    $temp = @$_GET[$variable]; break;
        case
'post':    $temp = @$_POST[$variable]; break;
        case
'cookie':    $temp = @$_COOKIE[$variable]; break;
    }
    switch(
$restrictions) {
        case
'alpha':        preg_match("/([a-zA-Z ,\.]+)/",$temp,$match); break;
        case
'alphanum':    preg_match("/([a-zA-Z0-9 ,\.]+)/",$temp,$match); break;
        case
'num':        preg_match("/([0-9]+)/",$temp,$match); break;
        case
'email':        preg_match("/^(([a-zA-Z0-9_-]*\.*)*[a-zA-Z0-9_-]+@[a-zA-Z0-
9_-]+(\.[a-zA-Z0-9_-]+)+)/"
,$temp,$match); break;
       
// add your own filters here   
   
}
    if(
$temp!='') {
        global $
$variable;
        $
$variable = $match[1];
        return
true;
    }
    return
false;
}
?>



Example, assuming register_globals is OFF
<?php
printf
("Before assigning the variable, it should be NOT be set.<br>" .
       
"The variable, 'test', is currently %s<hr>",
       isset(
$test) ? 'set' : 'NOT set'
       
);
printf("Now assigning the variable, '\$test'...<br>");
   
$result = assign('test','get','alpha');

printf("Here's what the function has done:<br>" .
       
"The function returned: %s <br>" .
       
"The value of \$test is: %s <hr>",
       
$result ? 'TRUE' : 'FALSE',
       
$test
       
);

?>
<form action=test.php method=get>
<input type=text name=test>
<input type=submit>
</form>



Function to generate readable/remeberable random password
Categories : PHP, Security, Security
A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
IPTables Bandwidth statics
Categories : PHP, Security, Network
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
using global variables
Categories : Global Variables, PHP
phpSecurePages is a PHP module to secures pages with a loginname and password. It handles multiple user groups (each has own viewing rights), store data in a MySQL database or a configuration file, and can be used to identify Web site viewers.
Categories : PHP, Security, Authentication
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Simple Password example
Categories : PHP, Authentication, Security, HTTP
Authenticator for Exchange Server LDAP
Categories : PHP, Authentication, LDAP, Security, Sessions
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Distribute PHP Software Protected by a License Key.
Categories : PHP, Cryptography, Security, Software
pick up an array of variables from a query string such as: http://www.archipro.com/test.php?state=AB&state=BC
Categories : PHP, Strings, URLs, Global Variables
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
Initialize global variables for every field in a table. This version requires that phplib is installed on your server.
Categories : Global Variables, MySQL, PHP, Variables
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library