Page 1 of 2

set a request variable, how

Posted: Tue Oct 26, 2010 1:57 am
by AGC
How do I use the set_var to set a request variable, for me, to use later ?

Thank

Re: set a request variable, how

Posted: Tue Oct 26, 2010 2:15 am
by 3Di
phpbb's request_var already uses set_var ..

Re: set a request variable, how

Posted: Tue Oct 26, 2010 2:02 pm
by AGC
I know. I want to set a variable right before requesting it.
I try to use set_var but nothing happend ??? how I use this function ?

Re: set a request variable, how

Posted: Tue Oct 26, 2010 2:32 pm
by Brf
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.

Re: set a request variable, how

Posted: Tue Oct 26, 2010 2:49 pm
by Erik Frèrejean

Code: Select all

// Set a variable to the $_REQUEST array
$_REQUEST['myvar'] = 'something'; 

Re: set a request variable, how

Posted: Wed Oct 27, 2010 1:28 am
by AGC
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
Erik Frèrejean wrote:

Code: Select all

// Set a variable to the $_REQUEST array
$_REQUEST['myvar'] = 'something'; 
Thank you for the Info.
But if I used it in a MOD is that forbidden ?

Re: set a request variable, how

Posted: Wed Oct 27, 2010 5:09 am
by Erik Frèrejean
I don't see why, as long you don't introduce an security issue with it. But only a MOD team member can give a conclusive answer to that, I'm not aware of all their policies.

Re: set a request variable, how

Posted: Wed Oct 27, 2010 3:09 pm
by igorw
Changing request variables is strongly discouraged because it no longer allows assumptions about superglobals to be made.

Re: set a request variable, how

Posted: Wed Oct 27, 2010 4:02 pm
by AGC
igorw wrote:Changing request variables is strongly discouraged because it no longer allows assumptions about superglobals to be made.
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.

Re: set a request variable, how

Posted: Wed Oct 27, 2010 4:51 pm
by Dr.Death
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);

Re: set a request variable, how

Posted: Wed Oct 27, 2010 5:45 pm
by igorw
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);
Please always cast though, related: http://blog.phpbb.com/2009/09/10/how-no ... quest_var/

Re: set a request variable, how

Posted: Thu Oct 28, 2010 1:00 am
by AGC
igorw wrote:
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);
Please always cast though, related: http://blog.phpbb.com/2009/09/10/how-no ... quest_var/
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.

Re: set a request variable, how

Posted: Thu Oct 28, 2010 9:39 am
by igorw
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.

Re: set a request variable, how

Posted: Fri Oct 29, 2010 1:29 am
by AGC
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.
Yes. I know that.
So if the variable is sanitized, I can set $_REQUEST['variable'] = $data as integer.
And then request_var() it later.

Thanks.

Re: set a request variable, how

Posted: Fri Oct 29, 2010 1:37 am
by 3Di
that should be:

Code: Select all

$default = (int) $database_value;
$input = request_var('input', $default);
or I am getting older..