set a request variable, how
Posted: Tue Oct 26, 2010 1:57 am
How do I use the set_var to set a request variable, for me, to use later ?
Thank
Thank
Home of phpBB
https://www.phpbb.com/community/
https://www.phpbb.com/community/viewtopic.php?f=71&t=2108294
Code: Select all
// Set a variable to the $_REQUEST array
$_REQUEST['myvar'] = 'something';
Brf wrote:set_var() is just for giving a script variable a value, using a type mask. It has nothing at all to do with request variables
Thank you for the Info.Erik Frèrejean wrote:Code: Select all
// Set a variable to the $_REQUEST array $_REQUEST['myvar'] = 'something';
What if I take a variable data from the database and set $_request and the variable not set before this action, I mean in the $_request array it's not exist yet.igorw wrote:Changing request variables is strongly discouraged because it no longer allows assumptions about superglobals to be made.
Code: Select all
$default = $database_value;
$input = request_var('input', $default);
Please always cast though, related: http://blog.phpbb.com/2009/09/10/how-no ... quest_var/Dr.Death wrote:You could set the default value of the request_var() to the database value.
Code: Select all
$default = $database_value; $input = request_var('input', $default);
First the variable is sanitized, with the sql_query, Second the variable would not write back to the database, But just will be request for later use.igorw wrote:Please always cast though, related: http://blog.phpbb.com/2009/09/10/how-no ... quest_var/Dr.Death wrote:You could set the default value of the request_var() to the database value.
Code: Select all
$default = $database_value; $input = request_var('input', $default);
Yes. I know that.igorw wrote:Let me state the conditions more clearly. If you expect $input to be an integer and want to use it in a query later on, you need to cast $default to an integer.
Code: Select all
$default = (int) $database_value;
$input = request_var('input', $default);