RE: Is there a shorthand way to...?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I didn't see this in any of the responses, and truthfully it's not the
best way or most secure.. .basically it has a lot of flaws that you
should watch out for (probably creates security issues more than any
other thing) but another option for mass setting variables that are
possible set or not is to use extract()

Extract() will take all the array items and assign the values to the
keys:

$_POST['courses_list'] = 'Used';

Extract($_POST);

Becomes...

$courses_list == 'Used'


But if $_POST['courses_list'] isn't set, then you get no $courses_set
variable.


If you do end up using this, pay attention to variables that you havn't
used yet that might be used later on.  If a variable isn't set, in this
case, if $courses_list isn't set, then extract() will put the value of
$_POST['courses_list'] into $courses_list.   If it IS set, and you use
one of the extract() parameters, you can make it NOT overwrite the
current $courses_list.  Which may be a good idea to prevent someone from
over-writing one of your security related variables.

I only mention this because I think it can be very useful.   I wouldn't
be as concerned with $_POST variables as I would with $_GET variables.
You don't want to make it so someone can go:

Yourscript.php?userauthneticated=1

Then do:

Extract($_GET);

Then you have...

$userauthenticated == 1


If you then have something like:

If ($userauthenticated) {
	# Some code that allows user to edit or view personal stuff,
demographics, passwords
      # etc...   Or even make changes to a database or other security
related stuff
}


That would be bad.


You may still end up having to do a isset($courses_list) to decide what
to do with the info later, but if you end up with 100 $_POST variables,
then extract() might help break those out for ya.

-TG

> -----Original Message-----
> From: Al [mailto:news@xxxxxxxxxxxxx] 
> Sent: Monday, November 22, 2004 9:01 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Is there a shorthand way to...?
> 
> 
> When handling $_POST[] values that may or may not be 
> assigned, I am forever using:
> 
> if((isset($_POST['courses_list']) AND 
> $_POST['courses_list']== 'Used'))
> 
> Is there a shorthand way of doing this without causing notice errors?
> 
> Thanks.....

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux