WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : 5327
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 
 

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>



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
A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
Simple Password example
Categories : PHP, Authentication, Security, HTTP
PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character.
Categories : PHP, Algorithms, Security, Authentication, Encryption
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
Secure URL $_GET
Categories : PHP, Data Validation, Security
Encoding data using PGP via PHP's proc_* functions
Categories : Cryptography, Security, Email, PHP, PGP
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
Easily Grant Temporary SSH Access to yourself when in remote location
Categories : PHP, Linux, Cron, Security
Distribute PHP Software Protected by a License Key.
Categories : PHP, Cryptography, Security, Software
using global variables
Categories : Global Variables, PHP
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page.
Categories : PHP, Sessions, Security, Authentication