|
|
|
|
|
|
| |
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 | | | Logging 404 errors in your custom statistics using Apache and a PHP script. Categories : Apache, Web Servers, PHP, Errors and Logging | | | error_log -- send an error message somewhere Categories : PHP, PHP Functions, Errors and Logging | | | A Custom Error Handling And Debugging Class Categories : PHP, PHP Classes, Debugging, Errors and Logging | | | Passing variables by reference. Categories : Variables, PHP | | | 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 | | | How to display a PHP variable value from a selectbox without reloading the
page by merging PHP and Javascript variables. Categories : PHP, Java Script, Variables | | | 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 | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Working with files - return an array of files within a directory Categories : PHP, Strings, Variables, Filesystem | | | Ping a Server and run a command to fix it if it is down Categories : PHP, Errors and Logging, Regexps | | | How to pass an array to a function, or how to define a
function wich recieves an array. Categories : Variables, PHP, Arrays | | | 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 | | | [PHP5] PHP Debugger and Helper Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML | | | Working with files - putting file contents to a string / var Categories : PHP, Filesystem, Variables, Strings | |
|
|