Below is a function adapted from one found in phpMyEdit.class .php
phpMyEdit is a form generator for PHP/MySQL.
I think this function works great, especially for forms where data is
redisplayed due to failed validation of user input. I wonder what the
opinion of other PHP users would be.
function get_cgi_var($na me, $default_value = null)
{
// From the phpMyEdit project
// Usage: $name = get_cgi_var('na me');
static $magic_quotes_g pc = null;
if ($magic_quotes_ gpc === null) {
$magic_quotes_g pc = get_magic_quote s_gpc();
}
global $HTTP_GET_VARS;
$var = @$HTTP_GET_VARS[$name];
if (! isset($var)) {
global $HTTP_POST_VARS ;
$var = @$HTTP_POST_VAR S[$name];
}
if (isset($var)) {
if ($magic_quotes_ gpc) {
if (is_array($var) ) {
foreach (array_keys($va r) as $key) {
$var[$key] = stripslashes(tr im(strip_tags($ var[$key])));
}
return $var;
} else {
$var = stripslashes(tr im(strip_tags($ var)));
}
}
} else {
$var = @$default_value ;
}
return $var;
// If data is displayed/posted using htmlspecialchar s($var)
// return @$HTTP_POST_VAR S ? html_entity_dec ode($var, ENT_QUOTES) :
$var;
};
$name = get_cgi_var('na me');
phpMyEdit is a form generator for PHP/MySQL.
I think this function works great, especially for forms where data is
redisplayed due to failed validation of user input. I wonder what the
opinion of other PHP users would be.
function get_cgi_var($na me, $default_value = null)
{
// From the phpMyEdit project
// Usage: $name = get_cgi_var('na me');
static $magic_quotes_g pc = null;
if ($magic_quotes_ gpc === null) {
$magic_quotes_g pc = get_magic_quote s_gpc();
}
global $HTTP_GET_VARS;
$var = @$HTTP_GET_VARS[$name];
if (! isset($var)) {
global $HTTP_POST_VARS ;
$var = @$HTTP_POST_VAR S[$name];
}
if (isset($var)) {
if ($magic_quotes_ gpc) {
if (is_array($var) ) {
foreach (array_keys($va r) as $key) {
$var[$key] = stripslashes(tr im(strip_tags($ var[$key])));
}
return $var;
} else {
$var = stripslashes(tr im(strip_tags($ var)));
}
}
} else {
$var = @$default_value ;
}
return $var;
// If data is displayed/posted using htmlspecialchar s($var)
// return @$HTTP_POST_VAR S ? html_entity_dec ode($var, ENT_QUOTES) :
$var;
};
$name = get_cgi_var('na me');
Comment