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