|
|
|
|
|
|
| |
PURPOSE:
Simply to keep PHP from geeking out when an undefined POST, GET, or SESSION variable
is meet, always returning a defined variable. (In particular for use in form check boxes.)
----
USAGE:
getvar( mixed var [, int ])
postvar( mixed var [, int ])
sessionvar( mixed var [, int ])
include_once("get_post.php");
Expecting $_GET["somevar"], use instead getvar("somevar")
Expecting $_POST["somevar"], use instead postvar("somevar")
Expecting $_SESSION["somevar"], use instead sessionvar("somevar")
Example:
$sql = "INSERT INTO tbl_something
SET some_column = " . postvar("checkbox_name",true) . ",
some_other_column = '" . postvar("text_box_name") . "'";
The first argment is the variable name, the second tells the function to return an int (0)
on false.
| <?php
/*
----
getvar/postvar - When you just don't know what to expect!
----
Brian Tafoya
briantafoya.com
"Taking over the planet one open source script at a time!"
----
PURPOSE:
Simply to keep PHP from geeking out when an undefined POST, GET, or SESSION variable
is meet, always returning a defined variable. (In particular for use in form check boxes.)
----
USAGE:
getvar( mixed var [, int ])
postvar( mixed var [, int ])
sessionvar( mixed var [, int ])
include_once("get_post.php");
Expecting $_GET["somevar"], use instead getvar("somevar")
Expecting $_POST["somevar"], use instead postvar("somevar")
Expecting $_SESSION["somevar"], use instead sessionvar("somevar")
Example:
$sql = "INSERT INTO tbl_something
SET some_column = " . postvar("checkbox_name",1) . ",
some_other_column = '" . postvar("text_box_name") . "'";
The first argment is the variable name, the second tells the function to return an int (0)
on false.
*/
/*
Prevent undefined get variables
*/
function getvar($name,$isint="") {
if(isset($_GET[$name])) {
return $_GET[$name];
} else {
if($isint) {
return 0;
} else {
return "";
}
}
}
/*
Prevent undefined post variables
*/
function postvar($name,$isint="") {
if(isset($_POST[$name])) {
return $_POST[$name];
} else {
if($isint) {
return 0;
} else {
return "";
}
}
}
/*
Prevent undefined session variables
*/
function sessionvar($name,$isint="") {
if(isset($_SESSION[$name])) {
return $_SESSION[$name];
} else {
if($isint) {
return 0;
} else {
return "";
}
}
}
?> | | |
|
| DB Connection Function with error handling and email failure notices Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | 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 | | | PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside. Categories : PHP, Arrays, Variables | | | translate.php - Assocciative array example, passing a reference to a function. Categories : PHP, Arrays, Languages, Variables | | | 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 | | | Intelligent 404 Handler Categories : PHP, Errors and Logging | | | How to control the number of decimal places when outputting numbers. Categories : PHP, Strings, Variables | | | Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays | | | Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem | | | 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 | | | Accessing GET and PUT variables with HTTP_GET_VARS on Win2K. Categories : PHP, Windows 2000, Variables | | | Visits-tracking Categories : PHP, Databases, MySQL, Errors and Logging, Functions | | | Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI Categories : Variables, PHP Options and Info, Arrays, URLs, PHP | | | Newbie Notes #5 - To double quote, or single quote, that is the question Categories : PHP, Beginner Guides, Variables | |
|
|
|