
Originally Posted by
diabolo
thank you!
another thing popped up. what happens if some sob comes and tries to use:
site.php?calendar&staff
I need a fail-safe so that it only executes the first command. but as far as i know foreach does not have a way to stop it, unlike while().
If you want just one option executed:
PHP Code:
# legal options
$permitted = array( 'compose' , 'destroy', 'giggle', 'whistle' );
# all options sent
$submitted = array_keys( $_GET ) ;
# legal options sent
$ok_submitted = array_intersect( $permitted , $submitted ) ;
## INSERT A TEST TO MAKE SURE AT LEAST ONE OPTION
foreach( $ok_submitted as $option ){
// Do something with $option
break ; # STOP AFTER ONE
}
Does not guarantee which will be executed.
If you list the options in order you want to perform, then something like
PHP Code:
# legal options
$permitted = array( 'compose' , 'destroy', 'giggle', 'whistle' );
# all options sent
$submitted = array_keys( $_GET ) ;
# legal options sent
$found_option = false ;
foreach( $permitted as $option ){
if( in_array( $option , $submitted ) ){
# DO SOMETHING WITH $option
$found_option = true ;
break;
}
}
# HANDLE CASE WHERE $found_option is false